自定义控件实现
来源:互联网 发布:气球兵升级数据 编辑:程序博客网 时间:2024/05/21 09:40
目标:自定义控件实现
步骤:
1)准备控件Layout,e.g.
navigation_header.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@android:color/holo_blue_light" android:orientation="horizontal" > <Button android:id="@+id/btn_left" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10.0dip" android:background="@drawable/ic_launcher" android:text="返回" android:textColor="@android:color/white" /> <TextView android:id="@+id/tv_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:singleLine="true" android:text="标题" android:textColor="@android:color/white" /> </LinearLayout>
2)准备自定义控件对应类,通常需要继承Layout类,实现其Constructor,注入刚才的layout 配置文件,e.g.
NavigationHeader.java
public class NavigationHeader extends LinearLayout {private Activity activity;private Button btn_left; private TextView tv_title; public NavigationHeader(Context context, AttributeSet attrs) {super(context, attrs);LayoutInflater layoutInflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); layoutInflater.inflate(R.layout.navigation_header, this);...
3)在XML中调用控件,e.g.
result.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <com.testApp5.NavigationHeader android:id="@+id/uiNavigationHeader" android:layout_width="fill_parent" android:layout_height="45dip" /> <TextView android:id="@+id/result" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="result content" /> </LinearLayout>
最基本的就是这些,更多的如自定义参数 可以参考以下blog:
Reference - http://blog.csdn.net/worker90/article/details/7909328
0 0
- 自定义控件实现控件间距
- 自定义控件实现信号灯
- android自定义控件实现
- 自定义控件实现信号灯
- DuiLib实现自定义控件
- Android自定义控件实现
- 自定义控件实现
- Android自定义控件实现
- 自定义控件的实现
- 自定义控件的实现
- 自定义控件的实现
- 自定义控件粗糙实现
- 自定义控件实现日历
- 自定义控件实现轮播图
- 自定义控件实现学习
- 【自定义控件】eat loading 自定义控件实现
- 利用自定义控件实现TextBox
- Android.自定义控件的实现
- Jenkins 邮件配置 (使用 Jenkins Email Extension Plugin)
- 粒子系统三种方法
- java语法糖第一发
- linphone-android编译(陆陆续续。。。。)
- .gitignore
- 自定义控件实现
- os作业3:银行家算法
- o(︶︿︶)o 唉,数据结构还没看完,导师又让我看java
- 四步完成Spring国际化动态配置
- Netty logo 高性能网络应用框架 Netty
- 5.9.1UI-Label
- 运算符重载
- url地址中的参数存储为对象
- 快速排序(QuickSort)