Reputation:
I have to use drawable in my code with icon, because I want to set background in my holder.
holder.itemView.setBackgroundResource(R.drawable.my_drawable);
itemView
is instance of View
.
Unfortunately I cannot set size attributes for in xml.
my_drawable.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="@color/background"/>
</item>
<item android:right="16dp">
<bitmap
android:src="@drawable/ic_android"
android:layout_width="18dp"
android:layout_height="18dp"
android:gravity="right|center_vertical"/>
</item>
</layer-list>
Question
Is it possible to set size of icon in my drawable ?
Upvotes: 0
Views: 1991
Reputation: 662
According to Android Developers and to this post Android bitmap image size in xml it is not possible to set the size in xml
Upvotes: 1
Reputation: 4669
In your Drawbles folder, there are subfolders. Each of those denotes a different size, sm, med, lg, xlg, etc...
Put the same image, at different sizes, with the exact same filename into those folders. The device will choose the most appropriate size automatically.
A good example would be your launcher icon. Eclipse will already provide you with like 5 default sizes for just this reason.
Upvotes: 0