Android自定义控件之组合控件学习笔记分享自定义控件之组合控件学习笔记分享
主要为大家分享了Android自定义控件之组合控件学习笔记,具有一定的实用性和参考价值,感兴趣的小伙伴们可以参考一
下
我们来讲一下自定义组合控件,相信大家也接触过自定义组合控件吧,话不多说,直接干(哈~哈~):
大家看到这个觉得这不是很简单的吗,这不就是写个布局文件就搞定嘛,没错,确实直接上布局就行,不过,我只是用这个简单的例子来
讲一下自定义组合控件的用法。
首先看看,这一行行的条目看起来都长得差不多,只是图片和文字不一样,没错,就是看中这一点,我们可以把一个条目做成一个组合控
件,做为一个整体,这样不管你有几个条目,就写几个组合控件就行了。
步骤:
1.先建立组合控件的布局先建立组合控件的布局
myView.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="60dp" >
<ImageView
android:id="@+id/icon_Iv"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
android:src="@drawable/phone_qiyi_explore_friends" />
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="80dp"
android:gravity="center"
android:text="朋友圈"
android:textSize="15sp"
android:textStyle="bold" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"