android UI(2)自定义控件简单使用
来源:互联网 发布:软件版权修改器 编辑:程序博客网 时间:2024/05/19 23:26
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" ><include android:id="@+id/title" layout="@layout/title" /> <TextView android:textSize="15sp" android:layout_gravity="center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="这个是首页" /> <com.example.demo1.BottomTitle android:id="@+id/buttomtitle" android:layout_width="match_parent" android:layout_height="wrap_content" > </com.example.demo1.BottomTitle></LinearLayout>
在这个 主activity的布局文件中 有两个标签 include和 com.example.demo1.BottomTitle
如果是要把一个简单的布局文件变成一个view 只需要用include标签导入这个layout文件
如果是一个自定义控件(有自己实现的功能比如点击就变色或者切换fragment等等) 可以new一个class 继承控件或者布局 在他的构造方法中描绘这个自定义控件
public class BottomTitle extends LinearLayout {public BottomTitle(Context context) {super(context);// TODO Auto-generated constructor stub}public BottomTitle(Context context, AttributeSet attrs) {super(context, attrs);// TODO Auto-generated constructor stubsetOrientation(LinearLayout.HORIZONTAL);Button button1 = new Button(getContext());button1.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1));button1.setText("首页");addView(button1);Button button2 = new Button(getContext());button2.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1));button2.setText("帮助");addView(button2);} }
参考文章 : 点击打开链接
0 0
- android UI(2)自定义控件简单使用
- QT自定义函数使用UI控件的简单方法
- Android UI-自定义日历控件
- Android UI-自定义日历控件
- Android UI-自定义日历控件
- Android UI-自定义日历控件
- Android 讲解:UI 自定义控件
- #Android源码#自定义UI控件
- Day3.2--Android简单UI控件之TextView的高级使用--SpannableString的使用
- Android L 新增UI控件:RecyclerView CardView的简单使用
- Android简单了解自定义控件和自定义属性如何使用
- Android 自定义控件 仿乐Phone UI
- android UI进阶之自定义组合控件
- android UI进阶之自定义组合控件
- android UI进阶之自定义组合控件
- android UI进阶之自定义组合控件
- android UI进阶之自定义组合控件
- android UI进阶之自定义组合控件
- android从service里面启动一个Activity
- NfcV(ISO 15693)读写操作
- Spring与Hibernate整合
- 每天进步一点点——sleep等时间延迟函数
- Fragment VS View
- android UI(2)自定义控件简单使用
- 转】Dolby TrueHD 、DTS-HD MA和LPCM比较解析!!
- poj1573 Robot Motion
- 关于uid和gid的问题
- TClientDataSet 操作和读入 xml 文件
- 岁月的歌
- 最多连续数的子集
- 我使用的深圳电信ADSL的宽带又要到期了
- java之ReferenceQueue