Imageview Size For Phones And Tablets
Solution 1:
It is surprising and very strange that no one could give an answer to this seemingly simple question. Well, accidentally I found a solution and it was just as simple
If you want show different image sizes for tablet and phones just create an dimen
for it
for phones we show small image with 50dp
<?xml version="1.0" encoding="utf-8"?><resources><dimenname="image_size">50dp</dimen></resources>
for tablet around 10" we show 2x size image with 100dp
<?xml version="1.0" encoding="utf-8"?><resources><dimenname="image_size">100dp</dimen></resources>
Then in ImageView tag specify size:
<ImageView
android:layout_width="@dimen/image_size"
android:layout_height="@dimen/image_size"
android:id="@+id/imgViewIcon"/>
And necessarily you must make images for phones for different density from original size 50dp and put them in MDPI, HDPI, XHDPI, XXHDPI folders. For tablet make image with 100dp and also generate for different density, then put it in drawable-wNNNdp-?dpi folders, where NNN - screen width and ? - l, m, h, xh, xxh, xxxh dpi. Exactly folders drawable-wNNNdp-?dpi is the answer
Solution 2:
Don't give fix size to imageview.Give imageview's height and width wrap_content in xml....
<ImageView
android:id="@+id/img"android:src="@drawable/splash"android:layout_width="wrap_content"android:layout_height="wrap_content"/>
Post a Comment for "Imageview Size For Phones And Tablets"