真机和模拟器图片显示不同Android
Different picture display in real device and emulator Android
真机和模拟器显示的图片不一样Android,不明白是什么原因
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/music"
android:contentDescription="@string/app_name"
android:layout_weight="0.5"
android:cropToPadding="false" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.9">
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:id="@+id/button" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:id="@+id/button2" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:id="@+id/button3" />
</LinearLayout>
这是它在模拟器和真实设备上的样子
我附上代码布局。我会很高兴得到任何帮助
Maintaining density independence is important because, without it, a
UI element (such as a button) appears physically larger on a
low-density screen and smaller on a high-density screen. Such
density-related size changes can cause problems in your application
layout and usability.
正如 Supporting Multiple Screens 文档中完美记录的那样,您需要支持多种屏幕尺寸的设备。将有针对各种密度的单独 Drawable
文件夹,将具有特定密度的图像放在相应文件夹中。
一组六个广义密度:
ldpi(低)~120dpi
mdpi(中等)~160dpi
hdpi(高)~240dpi
xhdpi(超高)~320dpi
xxhdpi(超超高)~480dpi
xxxhdpi(超高超高)~640dpi
首先你的图片 height
和 width
设置为 wrap_content
,
试试这个,但你需要一张高分辨率的图片,请参阅 Harsh Dattani 关于图片尺寸的回答,你的问题应该得到解决
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<ImageView
android:layout_width="fill_parent"<!--changed this-->
android:layout_height="fill_parent"<!--changed this-->
android:id="@+id/imageView"
android:src="@drawable/music"
android:scaleType="centerCrop"<!--added this line-->
android:contentDescription="@string/app_name"
android:layout_weight="0.5"
android:cropToPadding="false"
android:layout_gravity="center_horizontal" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.9">
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:id="@+id/button" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:id="@+id/button2" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:id="@+id/button3" />
</LinearLayout>
</LinearLayout>
真机和模拟器显示的图片不一样Android,不明白是什么原因
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/music"
android:contentDescription="@string/app_name"
android:layout_weight="0.5"
android:cropToPadding="false" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.9">
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:id="@+id/button" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:id="@+id/button2" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:id="@+id/button3" />
</LinearLayout>
这是它在模拟器和真实设备上的样子
我附上代码布局。我会很高兴得到任何帮助
Maintaining density independence is important because, without it, a UI element (such as a button) appears physically larger on a low-density screen and smaller on a high-density screen. Such density-related size changes can cause problems in your application layout and usability.
正如 Supporting Multiple Screens 文档中完美记录的那样,您需要支持多种屏幕尺寸的设备。将有针对各种密度的单独 Drawable
文件夹,将具有特定密度的图像放在相应文件夹中。
一组六个广义密度:
ldpi(低)~120dpi
mdpi(中等)~160dpi
hdpi(高)~240dpi
xhdpi(超高)~320dpi
xxhdpi(超超高)~480dpi
xxxhdpi(超高超高)~640dpi
首先你的图片 height
和 width
设置为 wrap_content
,
试试这个,但你需要一张高分辨率的图片,请参阅 Harsh Dattani 关于图片尺寸的回答,你的问题应该得到解决
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<ImageView
android:layout_width="fill_parent"<!--changed this-->
android:layout_height="fill_parent"<!--changed this-->
android:id="@+id/imageView"
android:src="@drawable/music"
android:scaleType="centerCrop"<!--added this line-->
android:contentDescription="@string/app_name"
android:layout_weight="0.5"
android:cropToPadding="false"
android:layout_gravity="center_horizontal" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.9">
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:id="@+id/button" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:id="@+id/button2" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:id="@+id/button3" />
</LinearLayout>
</LinearLayout>