之所以用得到这个技术,主要是在实际的项目开发中要反复去使用某个控件来实现文件选择的功能。因此想到了自定义控件的方法,将需要复用的控件及其事件响应统一封装:
好吧没接下来进入主题:
参考别人的博客介绍实现linearLayout的三种方式
方式1
在Linearlayout的构造函数中通过使用映射机制加载布局文件,即通过
Inflater方法,在使用该方法自定义的控件时,由于所有的子元素都是在运行时通过代码动态创建的,所以该控件只能以一个独立的控件形式在Layout文件中声明:
public class CustomLayout extends LinearLayout{
public CustomLayout(Context context){
LayoutInflater mInflater = LayoutInflater.from(context);
View myView = mInflater.inflate(R.layout.receive, null);
addView(myView);
}
}
布局文件
< LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
androidundefinedrientation="vertical" >
<LinearLayout
android:layout_width=