Nexussim Lements
Nexussim Lements

Reputation: 807

Android reduce size of icon inside image view

I have the following tabs in a List View , these are using an icon SVG inside an image view :

enter image description here

My problem is the SVG icon is very big and I need to resize it WITHOUT resizing the image view and its shape , I would like it something like this :

enter image description here

This is my code :

circle_shape.xml

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    
    <size
        android:width="160dp"
        android:height="160dp" />
    
</shape>

imageView:

  <ImageView
        android:id="@+id/ivLearnsetType"
        android:layout_width="36dp"
        android:layout_height="29dp"
        android:layout_marginBottom="25dp"
        android:gravity="center"
        android:scrollHorizontally="true"
        android:singleLine="true"
        android:text="@string/placeholder"
        android:textColor="@color/Black" />

Java:

        Integer color = PokemonUtils.getColorForType().get(convertedType);
        Drawable drawable = getContext().getDrawable(R.drawable.ic_bug_type_icon);
        ivLearnsetType.setImageDrawable(drawable);
        ivLearnsetType.setBackgroundResource(R.drawable.circle_shape);
        GradientDrawable ivDrawable = (GradientDrawable) ivLearnsetType.getBackground();
        ivDrawable.setColor(color);

Upvotes: 2

Views: 1611

Answers (3)

Dimple Dobariya
Dimple Dobariya

Reputation: 71

use android:scaleType="centerInside" in Imageview

Upvotes: 3

Samer Kasseb
Samer Kasseb

Reputation: 192

Add this to app/build.gradle for support

defaultConfig {
    vectorDrawables.useSupportLibrary = true
}

in onCreate method add this.

AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);

Upvotes: 2

Vishnu
Vishnu

Reputation: 785

Try using android:scaleType="fitXY"

Here's the full code...

<ImageView
    android:id="@+id/ivLearnsetType"
    android:layout_width="36dp"
    android:layout_height="29dp"
    android:layout_marginBottom="25dp"
    android:gravity="center"
    android:scaleType="fitXY"
    android:scrollHorizontally="true"
    android:singleLine="true"
    android:text="@string/placeholder"
    android:textColor="@color/Black" />

Hope this helps...Feel free to ask for clarifications...

Upvotes: 1

Related Questions