Resize drawable image in TextView android
Solution 1
Try :
android:scaleX="0.7"
android:scaleY="0.7"
OR
Wrap your resource in a drawable that defines your desired size similar to:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="@drawable/icon"
android:width="@dimen/icon_size"
android:height="@dimen/icon_size"
/>
</layer-list >
then use it in drawable left.
Solution 2
there is only one solution take image view for the image and resize image but text display image right side . you used below code and i hope your issue solved..
<?xml version="1.0" encoding="utf-8"?>
<ImageView
android:id="@+id/icon"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_person" />
<TextView
android:id="@+id/heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:drawablePadding="5dp"
android:gravity="top"
android:padding="5dp"
android:singleLine="true"
android:text="heading"
android:textSize="20dp"
app:layout_constraintLeft_toRightOf="@+id/icon" />
Stu_Dent
A lifetime student who enjoyed a second career from taking an intensive/inundated learning materials and asking questions, a lot of questions which I found progressively consolidate my knowledge dramatically. I herewith deeply thank you so much to everyone in StackOverflow/StackExchange for your contribution and toleration to answer my questions. P.S Stu Dent is not my real name but I'm a student in all aspect. Thanks Pat
Updated on July 09, 2022Comments
-
Stu_Dent almost 2 years
Wonder how to resize an image inside a
TextView
xml in aLinearLayout
. I read some solution usingsetCompoundDrawablesWithIntrinsicBounds
method, but cannot get it right.Here is the image:
I want to reduce the size of the logo.
Here is my TextView code:
<TextView android:id="@+id/heading" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableLeft="@drawable/android_logo" android:drawableStart="@drawable/android_logo" android:gravity="top" android:padding="16dp" android:singleLine="true" android:text="@string/heading" android:textSize="20dp" android:drawablePadding="5dp"/>
-
Stu_Dent about 6 yearsThe 2nd suggestion works with TextView with the image. Thanks for the solution!
-
Vidhi Dave about 6 years@PattyPutty Happy to help :) Happy coding :)
-
Zmiter about 4 yearsNote "width" and "height" item attributes don't work in Android versions older than 6.0.