您的位置:首页 > 其它

如何动态设置ImageView的宽高以及位置

2011-10-15 23:06 417 查看
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);

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: