android.view.ViewGroup.LayoutParams介绍
2012-04-18 16:22
344 查看
1 | public static class |
2 | ViewGroup.LayoutParams |
3 | extends Object |
4 |
5 | java.lang.Object |
6 | ↳ android.view.ViewGroup.LayoutParams //继承关系 |
view(子视图) 向 parent view(父视图)传达自己的意愿的一个东西
父视图可以简单理解成一个LinearLayout
和 这个LinearLayout里边一个 TextView 的关系
TextView
就算LinearLayout的子视图 child view 。
每个不同的ViewGroup都有自己的LayoutParams子类,比如LinearLayout
也有自己的 LayoutParams
1 | LinearLayout.LayoutParams p = new LinearLayout.LayoutParams( |
2 | LinearLayout.LayoutParams.FILL_PARENT, |
3 | LinearLayout.LayoutParams.WRAP_CONTENT |
4 | ); |
5 | //调用addView()方法增加一个TextView到线性布局中 |
6 | mLayout.addView(textView, p); |
7 | //比较简单的一个例子 |
1 | LinearLayout.LayoutParams param1 = new LinearLayout.LayoutParams( |
2 | LinearLayout.LayoutParams.FILL_PARENT, |
3 | LinearLayout.LayoutParams.WRAP_CONTENT); |
4 | myTextView.setText(R.string.title); |
5 | myTextView.setTextColor(getResources().getColor(R.drawable.blue)); |
6 |
7 | /* 将TextView加到myLinearLayout */ |
8 | myLinearLayout.addView(myTextView, param1); |
然后把这个作为myTextView的参数了。这很好的体现了LayoutParams的作用。
notes:只能对自己的子类做这样的设定。
相关文章推荐
- android.view.ViewGroup.LayoutParams介绍
- android.view.ViewGroup.LayoutParams介绍
- java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.L(转)
- 异常:java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.view.
- android.view.ViewGroup$LayoutParams cannot be cast to android.widget.TableRow$LayoutParams
- android.view.ViewGroup$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutParams
- 解决 android.view.ViewGroup$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
- java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.
- android ViewGroup中的LayoutParams的理解和说明
- (转)Android控件 - ViewGroup、ViewGroup.LayoutParams、ViewGroup.MarginLayoutParams简介
- java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.view.ViewGroup$MarginLayoutParams
- android.view.ViewGroup$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
- Android控件 - ViewGroup、ViewGroup.LayoutParams、ViewGroup.MarginLayoutParams简介
- LayoutParams继承于Android.View.ViewGroup.LayoutParams(转)
- LayoutParams继承于Android.View.ViewGroup.LayoutParams.
- LayoutParams继承于Android.View.ViewGroup.LayoutParams.
- LayoutParams继承于Android.View.ViewGroup.LayoutParams.
- 解决 android.view.ViewGroup$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
- java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.R
- LayoutParams继承于Android.View.ViewGroup.LayoutParams.