我正在寻找创建一个自定义按钮。理想情况下,该按钮左侧有一个图像,右侧有一个文本视图。我将如何实现这个目标?
最快的方法
创建可点击的视图,其中包含 ImageView 和 TextView,并以可绘制按钮作为背景。
<RelativeLayout
android:clickable="true"
android:background="@android:drawable/btn_default"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/image"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@android:drawable/ic_input_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>
<TextView
android:id="@+id/text"
android:text="Sample text"
android:textAppearance="?android:attr/textAppearanceButton"
android:layout_toRightOf="@id/image"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
</RelativeLayout>
另一种方式
创建您自己的类,扩展RelativeLayout,如上设置内容视图,添加自定义方法来设置文本、图像等,仅此而已。
使用您的自定义布局。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)