layout = (LinearLayout) findViewById(R.id.testpicture);
imageView = (ImageView)findViewById(R.id.image);
layout.setBackgroundResource(R.drawable.a7777);
//获取手机的宽度,px
// WindowManager mWindowManager = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
// DisplayMetrics metrics = new DisplayMetrics();
// mWindowManager.getDefaultDisplay().getMetrics(metrics);
//
//获取手机的宽度的第二种方法
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int width = metrics.widthPixels;
int height = metrics.heightPixels;
Log.e("sydlog", "width=" + width);
Log.e("sydlog", "height=" + height);
// 把dp转换成px
int mDp2Px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, getResources().getDisplayMetrics());
//设置控件的宽和高
layout.getLayoutParams().width = width*3/2;
imageView.getLayoutParams().width = width;
//
// Log.e("sydlog", "imageView.getLayoutParams().width=" + imageView.getLayoutParams().width);
//
//移动控件
Animation animation = AnimationUtils.loadAnimation(this, R.anim.trans);
Animation animation1 = AnimationUtils.loadAnimation(this, R.anim.trans1);
layout.setAnimation(animation);
imageView.setAnimation(animation1);
startActivity(new Intent(this, Main.class));
//设置Activity之间切换的动画效果
overridePendingTransition(R.anim.wkzf_home_in, R.anim.wkzf_wujiepay_out);
//动态定义animation的另外一种方法
animation = new TranslateAnimation(0, -200, 0, 0);
animation1 = new TranslateAnimation(0, 200, 0, 0);
animation.setDuration(3000);
animation1.setDuration(3000);
animation.setFillAfter(true);
animation1.setFillAfter(true);
mLinearLayout.startAnimation(animation);
mImageView.startAnimation(animation1);
//动画效果的xml文件
<?xml version="1.0" encoding="utf-8"?>
<!-- 上下滑入式 -->
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate android:fromXDelta="0" android:toXDelta="-200" android:duration="5000"/>
</set>