Issue
I'm trying to use the ic_library_books_black_48dp Material Icon as a file-type icon in a file-listing view.
The largest available file, ic_library_books_black_48dp.png, comes in the following densities
drawable-mdpi
drawable-hpi
drawable-xhdpi
drawable-xxhdpi
drawable-xxxhdpi
Because image-file types display a thumbnail preview, larger icons are required for consistency. They were adjusted to 144x144 dp:
<ImageView
android:id="@+id/grid_item_iv"
android:layout_width="144dp"
android:layout_height="144dp"/>
Here is a zoomed in view of a prototype on an xhdpi device:
note: zoom in browser to see pixelation differences.
I wasn't happy with the provided xhdpi resolution, so I made copies of the xxhdpi and xxxhdpi versions, renamed them accordingly, and put them into drawable-xhdpi folder
resources
drawable-xhdpi
ic_library_books_black_48dp.png
ic_library_books_black_48dp_xxhdpi.png
ic_library_books_black_48dp_xxxhdpi.png
They were then assigned in GetView()
switch (fileType)
{
case AttachmentFileType.FileType.Docs:
iv.SetImageResource(Resource.Drawable.ic_library_books_black_48dp);
break;
case AttachmentFileType.FileType.Audio:
iv.SetImageResource(Resource.Drawable.ic_library_books_black_48dp_xxhdpi);
break;
case AttachmentFileType.FileType.Images:
iv.SetImageResource(Resource.Drawable.ic_library_books_black_48dp_xxxhdpi);
break;
default:
iv.SetImageResource(Resource.Drawable.ic_attachment_test);
break;
}
I prefer the clarity of ic_library_books_black_48dp_xxxhdpi.png scaled up to 144x144 dp on my xhdp device. However, this approach will not work on higher density screens (xxhdpi, xxxhdpi) because xxxhdpi is the highest provided version of the ic_library_books_black_48dp.png. To support xxhdpi and xxxhdpi I would need a xxxxhdpi and xxxxxhdpi version of icon (ie, "two grades higher"), respectively. Is there a way to make this work without resulting to creating custom icons (can android studio or maybe an editing program upscale while maintaining pixel density)?
Solution
If you can, I’d use vector graphics. They are supported right from Android Studio.
File -> New -> Vector Graphic
.
Then tap the Icon to “search”… find your Library Book icon…
Next and finish it. (don’t need to change anything here).
If you’re above API 21, then you’re good to go, you can reference it like any other icon.
If you need support to lower APIs, read the official Android Documentation about Vector Drawables.
Additionally, read all about Android Studio support here.
Answered By - Martin Marconcini
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.