TextView宽度匹配drawableTop宽度 [英] TextView width match drawableTop width
本文介绍了TextView宽度匹配drawableTop宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有办法使TextView width
匹配复合可绘制宽度(XML)?
Is there someway to make TextView width
match compound Drawable width (XML)?
例如xml代码:
<TextView
android:id="@+id/textView"
style="@style/TextIcons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/icon_contact"
android:gravity="center"
android:lines="2"
android:text="@string/contact_label" />
我得到:
|---------------------|
| |-------------| |
| | | |
| | Drawable | |
| | View | |
| | | |
| |-------------| |
|[---Contact Label---]|
|---------------------|
但是我真正想要的是:
|-----------------|
| |-------------| |
| | | |
| | Drawable | |
| | View | |
| | | |
| |-------------| |
| [---Contact---] |
| [----Label----] |
|-----------------|
推荐答案
您只需将图像和TextView分成相对的布局即可使它正常工作.可以很容易地指定将某些视图的边缘等对齐的位置.
You can simply get it to work by separating the image and the TextView, into a relative layout. It makes easy to specify where align some view's edges, etc.
下面的代码应该做的事情接近您想要的:
The following code should do something close to what you want:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon_contact"
android:id="@+id/imageView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp">
</ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/contact_label"
android:id="@+id/textView"
android:layout_below="@+id/imageView"
android:layout_alignRight="@+id/imageView"
android:layout_alignLeft="@+id/imageView"/>
</RelativeLayout>
这篇关于TextView宽度匹配drawableTop宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文