如何动态的获取和设置ImageView的宽度和高度
1个回答
2016-08-02 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
动态的获取和设置ImageView的宽度和高度,参考实例如下:
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);
}
}
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);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询