- 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);
- }
- }
如何动态设置ImageView的宽高以及位置
最新推荐文章于 2022-05-19 13:51:07 发布