android.view.ViewGroup.LayoutParams介绍
来源:互联网 发布:大众网络报停刊 编辑:程序博客网 时间:2024/05/16 19:36
1
public
static
class
2
ViewGroup.LayoutParams
3
extends
Object
4
5
java.lang.Object
6
↳ android.view.ViewGroup.LayoutParams
//继承关系
其实这个LayoutParams类是用于child 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
//比较简单的一个例子
LayoutParams 可以理解为layout的包信息,其中包含了各种数据。 如下:
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介绍
- Android View.ViewGroup.LayoutParams
- LayoutParams继承于Android.View.ViewGroup.LayoutParams.
- LayoutParams继承于Android.View.ViewGroup.LayoutParams.
- LayoutParams继承于Android.View.ViewGroup.LayoutParams.
- java.lang.ClassCastException: android.view.ViewGroup$LayoutParams错误
- 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.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.view.
- viewgroup如何感知view的LayoutParams
- 【Android 开发教程】View和ViewGroup介绍
- android之View和ViewGroup介绍
- Android中View和ViewGroup介绍
- Android中View和ViewGroup介绍
- 【android之View和ViewGroup介绍】
- 堆栈
- 创建控件
- linux开机启动服务和chkconfig使用方法
- GUI程序设计
- php处理全局变量
- android.view.ViewGroup.LayoutParams介绍
- 5 simple ways to troubleshoot using Strace
- I/O多路转接
- AT&T语法和Intel语法x86汇编的区别
- Android学习笔记(十):Activity-TableLayout和ScrollView
- 好久没来了,来看看
- 共有IP和私有IP以及IP地址的分类
- spring 下配置 proxool
- HTML5 Web Worker的使用方法