Android уменьшить размер значка внутри изображения - PullRequest
0 голосов
/ 09 июля 2020

У меня есть следующие вкладки в представлении списка, они используют значок SVG внутри представления изображения:

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"?>
  

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);

Ответы [ 3 ]

1 голос
/ 09 июля 2020

Добавьте это в app / build.gradle для поддержки

defaultConfig {
    vectorDrawables.useSupportLibrary = true
}

в методе onCreate добавьте это.

AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
1 голос
/ 09 июля 2020

используйте android: scaleType = "centerInside" в Imageview

1 голос
/ 09 июля 2020

Попробуйте использовать android:scaleType="fitXY"

Вот полный код ...

<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" />

Надеюсь, это поможет ... Не стесняйтесь спрашивать разъяснения ...

...