安卓开发之控件的大小获取和动态改变
2016-11-23 14:02
351 查看
动态设置控件大小:
其中的头文件不要弄错了:import android.view.ViewGroup.LayoutParams;
LayoutParams para = bt1.getLayoutParams();//bt1为按钮
para.width=200;//修改宽度
para.height=300;//修改高度
bt1.setLayoutParams(para); //设置修改后的布局。
获取控件大小:
int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
sb.measure(w, h);
int height = sb.getMeasuredHeight();
int width = sb.getMeasuredWidth();
注:在onCreate使用getHeight()是无法获取控件高的,一直未0,因为没有绘制完成,只能在onCreate走完后才能调用getHeight()获取。
其中的头文件不要弄错了:import android.view.ViewGroup.LayoutParams;
LayoutParams para = bt1.getLayoutParams();//bt1为按钮
para.width=200;//修改宽度
para.height=300;//修改高度
bt1.setLayoutParams(para); //设置修改后的布局。
获取控件大小:
int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
sb.measure(w, h);
int height = sb.getMeasuredHeight();
int width = sb.getMeasuredWidth();
注:在onCreate使用getHeight()是无法获取控件高的,一直未0,因为没有绘制完成,只能在onCreate走完后才能调用getHeight()获取。
相关文章推荐
- IOS开发UI篇--使用CAShapeLayer实现一个音量大小动态改变的控件
- 关于动态改变控件大小的一点不同的看法(转)
- 在.Net的WinForm开发中如何实现控件随窗体大小的改变而自动适应其改变<收藏>
- VC中动态改变控件和对话框字体(大小)
- Windows Phone开发经验谈(15)-动态的改变APP的字体大小
- 动态改变Android控件大小
- c# 动态改变控件大小的方法
- vb.net中运行时动态改变控件大小
- VC中动态改变控件和对话框字体(大小)
- 使用JavaScript实现动态改变控件大小
- 动态改变Android控件大小
- 动态改变对话框中控件的大小
- cedit cstatic控件动态生成及字体大小改变
- 在.Net的WinForm开发中如何实现控件随窗体大小的改变而自动适应其改变
- 获取屏幕大小和动态控制控件大小
- 动态改变Android控件大小
- 动态改变Android控件大小
- 动态改变控件大小
- android 动态改变控件位置和大小
- Android之动态改变控件大小