Set TextView width according to other View's width
I have a ImageView, the image is loaded from the net and can vary in
width. Below I have a TextView with a description of the image. I want the
TextView to be exactly as wide as the ImageView.
My try was this:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical" >
<ImageView
android:id="@+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
<TextView
android:id="@+id/imagedescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textAppearance="@style/SmallTextGray" />
</LinearLayout>
which somehow works as the TextView's width is set accoring to that of the
ImageView, but the TextView end after 2 lines:
I know I could set the TextView's width programmatically after I know the
image's width, but is there also a way to do it in the XML layout?
No comments:
Post a Comment