如何动态设置ImageView的宽高以及位置
package com.pic;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
public class PicTest extends Activity {
private final String TAG = "Pictrue Test!!!";
private ImageView image;
private int height = 0;
private int width = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
image = (ImageView)findViewById(R.id.ImageView01);
//height = image.getHeight();
//width = image.getWidth();
//Log.d(TAG, "height: " + height);
//Log.d(TAG, "width: " + width);
LayoutParams para;
para = image.getLayoutParams();
Log.d(TAG, "layout height0: " + para.height);
Log.d(TAG, "layout width0: " + para.width);
para.height = 300;
para.width = 300;
image.setLayoutParams(para);
Log.d(TAG, "layout height: " + para.height);
Log.d(TAG, "layout width: " + para.width);
}
}另外一种方法是 RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(dm.widthPixels, dm.heightPixels/2-30);
top_image.setLayoutParams(param);
摘自:http://www.01yun.com/mobile_development/20130321/258529.html