Is there someway to make TextView width
match compound Drawable width (XML)?
For example for xml code:
<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" />
I get:
|---------------------|
| |-------------| |
| | | |
| | Drawable | |
| | View | |
| | | |
| |-------------| |
|[---Contact Label---]|
|---------------------|
But what i really want is:
|-----------------|
| |-------------| |
| | | |
| | Drawable | |
| | View | |
| | | |
| |-------------| |
| [---Contact---] |
| [----Label----] |
|-----------------|
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.