#1.简介
TextView里定义的方法,据说是设置文本区域的宽高
android:maxWidth 关联方法: setMaxWidth(int) 属性说明: 设置文本区域的最大宽度
android:maxHeight 关联方法: setMaxHeight(int) 属性说明: 设置文本区域的最大高度
android:minWidth 关联方法: setMinWidth(int) 属性说明: 设置文本区域的最小宽度
android:minHeight 关联方法: setMinHeight(int) 属性说明: 设置文本区域的最小高度

View里定义的方法,只有设置视图最小宽高的方法,没有设置视图最大宽高的方法
android:minHeight 关联方法: setMinimumHeight(int) 属性说明: 设置视图最小高度
android:minWidth 关联方法: setMinimumWidth(int) 属性说明: 设置视图最小宽度

#2.代码分析

/** * @author LGY * @time 2017-12-13 * @action 经过测试我们知道, * 这是TextView里定义的方法,就目前测试而言,Button是无法通过这几个方法设置小宽高的,button要设置最小宽度只能通过setMinimumWidth和setMinimumHeightandroid:maxWidth 关联方法: setMaxWidth(int) 属性说明: 设置文本区域的最大宽度android:maxHeight 关联方法: setMaxHeight(int) 属性说明: 设置文本区域的最大高度android:minWidth 关联方法: setMinWidth(int) 属性说明: 设置文本区域的最小宽度android:minHeight 关联方法: setMinHeight(int) 属性说明: 设置文本区域的最小高度这两个方法是View里定义的,只有设置视图最小宽高的方法,没有设置视图最大宽高的方法android:minHeight 关联方法: setMinimumHeight(int) 属性说明: 设置视图最小高度android:minWidth 关联方法: setMinimumWidth(int) 属性说明: 设置视图最小宽度 */public class TestWidth extends Activity{private LinearLayout bodyLayout = null;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);initView();setContentView(bodyLayout);}private void initView(){LinearLayout.LayoutParams params = null;try {bodyLayout = new LinearLayout(this);if (bodyLayout!=null) {bodyLayout.setOrientation(LinearLayout.VERTICAL);params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);if (params!=null) {bodyLayout.setLayoutParams(params);}LinearLayout layout = new LinearLayout(this);if (layout!=null) {layout.setOrientation(LinearLayout.VERTICAL);params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);if (params!=null) {layout.setLayoutParams(params);}layout.setMinimumHeight(100);layout.setBackgroundColor(Color.YELLOW);bodyLayout.addView(layout);}TextView textTv = new TextView(this);if (textTv!=null) {textTv.setText("测试");//对于TextView,不管是调用setMinHeight还是setMinimumHeight都可以设置最小高度textTv.setMinHeight(300);//textTv.setMinimumHeight(300);textTv.setBackgroundColor(Color.RED);bodyLayout.addView(textTv);}//在没有设置setLayoutParams的高为LayoutParams.MATCH_PARENT的情况下,通过setMaxHeight是可以设置最大高度的TextView textTv2 = new TextView(this);if (textTv2!=null) {//params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);//if (params!=null) {//textTv2.setLayoutParams(params);//}textTv2.setText("测试2dddddddddddddddddddd" +"测试2dddddddddddddddddddd" +"测试2dddddddddddddddddddd" +"测试2dddddddddddddddddddd" +"测试2dddddddddddddddddddd" +"测试2dddddddddddddddddddd" +"测试2dddddddddddddddddddd" +"测试2dddddddddddddddddddd" +"测试2dddddddddddddddddddd" +"测试2dddddddddddddddddddd" +"测试2dddddddddddddddddddd" +"测试2dddddddddddddddddddd" +"测试2dddddddddddddddddddd" +"测试2dddddddddddddddddddd" +"测试2dddddddddddddddddddd" +"测试2dddddddddddddddddddd" +"测试2dddddddddddddddddddd" +"测试2dddddddddddddddddddd" +"测试2dddddddddddddddddddd" +"测试2dddddddddddddddddddd" +"测试2dddddddddddddddddddd" +"测试2dddddddddddddddddddd" +"测试2dddddddddddddddddddd" +"测试2dddddddddddddddddddd" +"测试2dddddddddddddddddddd" +"测试2dddddddddddddddddddd" +"测试2dddddddddddddddddddd" +"测试2dddddddddddddddddddd");textTv2.setMaxHeight(100);textTv2.setBackgroundColor(Color.WHITE);bodyLayout.addView(textTv2);}//ButtonButton btn = new Button(this);if (btn!=null) {btn.setText("Button");//Button无法通过setMinHeight设置最小高度textTv.setMinHeight(100);//Button通过setMinimumHeight可以设置最小高度//btn.setMinimumHeight(100);btn.setBackgroundColor(Color.BLUE);bodyLayout.addView(btn);}ImageView imageView = new ImageView(this);if (imageView!=null){imageView.setImageResource(R.drawable.ic_launcher);//ImageView因为继承的是View所以没有setMinHeight方法,//imageView.setMinHeight(300);//ImageView通过setMinimumHeight可以设置最小高度imageView.setMinimumHeight(300);bodyLayout.addView(imageView);}EditText editText = new EditText(this);if (editText!=null){//EditText可以通过setMinHeight方法设置最小高度,效果和setMinimumHeight一样editText.setMinHeight(300);//EditText通过setMinimumHeight可以设置最小高度//editText.setMinimumHeight(300);editText.setHint("TEST");bodyLayout.addView(editText);}}} catch (Exception e) {}}}

#3.总结
(1)LinearLayout等继承ViewGroup的布局,因为ViewGroup也是继承View的,所以LinearLayout也只有setMinimumHeight和setMinimumWidth设置最小宽高的方法,但是并没有设置最大宽高的方法。
(2)Button,EditView等都是继承了TextView,EditView可以通过setMinHeight设置最小高度,但是Button不行,Button必须通过setMinimumHeight才能设置最小高度。
#4.源码地址
http://download.csdn.net/download/lgywsdy/10156936

更多相关文章

  1. Android的布局方法
  2. 修改android 睡眠的时间的两种方法
  3. Android 设置颜色的方法总结
  4. Android帧率测试
  5. Android 中两种方法设置android:gravity 和 android:layout_grav
  6. 在eclipse的android工程里引用android sdk之外的类和方法

随机推荐

  1. [置顶] android调用第三方库——第四篇—
  2. android 控件位置常用布局
  3. 修改android 睡眠的时间的两种方法
  4. Android(安卓)模拟器
  5. android之inputType属性
  6. android SDK2.3 更新改动翻译
  7. Android开发你需要具备的基本功
  8. Android中对Log日志文件的分析
  9. Android(安卓)Studio 网络调试
  10. 基于百度地图实现Android定位功能实现(详