《第一行代码》复习四 自定义控件

来源:互联网 发布:数据标准化处理方法 编辑:程序博客网 时间:2024/05/03 18:29

这次写的是第一行代码上的自定义控件感觉是最简单的(之前看了一个更复杂的)不过这次只是复习 所以先吧这个简单的贴出来



上代码:

先写出自定义控件的布局:

应该很简单 就上一个LinearLayout 里水平放3个TextView

自定义 TiteLayout  类

public class TitleLayout extends LinearLayout {        //重写它的构造方法    public TitleLayout(Context context, AttributeSet attrs) {        super(context, attrs);        //加载布局文件        LayoutInflater.from(context).inflate(R.layout.title_bar, this);    }}

在 main.xml文件使用 包名加自定义的类名

<com.zuoni.uicustomviews.TitleLayout    android:layout_width="match_parent"    android:layout_height="wrap_content"></com.zuoni.uicustomviews.TitleLayout>
最后在Activity 中创建点击事件

0 0
原创粉丝点击