Android自定义按钮里面有imageview和textview? [英] Android Custom button with imageview and textview inside?
本文介绍了Android自定义按钮里面有imageview和textview?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一个自定义按钮.理想情况下,此按钮的左侧应为图片,右侧为textview.我该怎么办?
I'm looking to create a custom button. This button ideally would have an image on the left and a textview on the right. How would I accomplish this?
推荐答案
最快的方法
使用可绘制的Button作为背景创建可点击的视图,其中包含ImageView和TextView.
The fastest way
Create clickable View with Button drawable as background that contains ImageView and 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,如上所述设置内容视图,添加自定义方法来设置文本,图像等,仅此而已.使用您的自定义布局.
Other way
Create your own class, extend RelativeLayout, set content view as above, add custom methods to set text, image etc. and that's all. Use your custom layout.
这篇关于Android自定义按钮里面有imageview和textview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文