动态的获取和设置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;
        
   
    @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);
        
    }




你可能感兴趣的:(Activity及组件)