Reputation: 3026
I have a TextView and a ImageView in a horizontal linear layout. Is it possible to scale the ImageView so that it is relative to the size of the TextView in the layout file?
Basically I want something like :-
Instead of something like this
The layout file would be
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView />
<TextView />
</LinearLayout>
Upvotes: 8
Views: 6681
Reputation: 9700
Yeah, you can scale down the ImageView
at the height relative to the TextView
. To match the height of TextView
, set match_parent
to android:layout_height
for ImageView
which will help the ImageView
to take the height of TextView
. Try as follows...
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="30sp" />
</LinearLayout>
You can also achieve the same result as below way...
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_launcher"
android:text="TextView"
android:gravity="center_vertical"
android:textSize="30sp" />
Upvotes: 8
Reputation: 65
By using this you can simply add images inside your textview
<TextView>
android:drawableLeft="@drawable/picture.png"
</TextView>
Upvotes: -1
Reputation: 937
Try this
<TextView
android:id="@+id/Text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/image"
/>
Upvotes: -1