问题
I am using an imageview in my xml and setting an image from res/drawable-xhdpi to it. My image is of 354x404 in size and when i am running the code on a 10" samsung tablet, it showing the image as 177x202.
Here is the code which i am using:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false" >
<ImageView
android:id="@+id/img_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/app_name"
android:src="@drawable/android1" />
</LinearLayout>
Here is the image which i am using:
And this is the screenshot of the tablet:
Please tell why it is happening and what is the solution to resolve this problem.
Update: when i putting this image in "res/drawable" folder instead of xhdpi, it showing the image correctly i.e. 354x404.
回答1:
Edit after comments:
The ImageView will render the image inside of it at the correct resolution for the device. As per the documentation on providing resources, you must make sure that you provide resources at the correct DPI for each of the resolution types. Android will pick the best resource resolution for you, but if only one resource exists then it will pick that one and try to render at the device resolution.
Samsung tablets, while they have a large screen, are MDPI (the Galaxy Tab 2, at least) which is the standard density even though it has a large screen. Resources for it should be placed in res/drawable
.
来源:https://stackoverflow.com/questions/14019637/unexpected-behaviour-while-setting-a-image-from-res-folder-to-an-image-view-in-a