【发布时间】:2014-06-08 03:22:36
【问题描述】:
我在布局文件夹中创建了 android 布局,我的设备英寸为 3.2 到 5 英寸,属于普通屏幕,仅针对此设备,但我的布局在 3.2 英寸和 4 英寸方面彼此不同。
【问题讨论】:
标签: android layout screen between difference
我在布局文件夹中创建了 android 布局,我的设备英寸为 3.2 到 5 英寸,属于普通屏幕,仅针对此设备,但我的布局在 3.2 英寸和 4 英寸方面彼此不同。
【问题讨论】:
标签: android layout screen between difference
您可以在 java 中获取屏幕大小问题并进行检查
【讨论】:
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-small/my_layout.xml // layout for small screen size
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
res/drawable-mdpi/my_icon.png // bitmap for medium density
res/drawable-hdpi/my_icon.png // bitmap for high density
res/drawable-xhdpi/my_icon.png // bitmap for extra high density
【讨论】:
关注:Supporting multiple screen size - Android
像这样定义你的维度值
res/values-sw600dp/dimen.xml -> 7+ inches
res/values-sw720dp/dimen.xml -> 10+ inches
values-w360dp
values-w500dp
values-w480dp
values-xlarge
values-v11
values-v14
Sherlock Bar检查那里
【讨论】:
您需要为此创建不同的文件夹
例如
布局文件夹/main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background"
android:orientation="vertical" >
<Button
android:id="@+id/rate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Rate us"
android:textColor="@color/black_font" />
</RelativeLayout>
layout-large/main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background"
android:orientation="vertical" >
<Button
android:id="@+id/rate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Rate us"
android:textColor="@color/black_font"
android:textSize="30sp" />
</RelativeLayout>
layout-xlarge/main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background"
android:orientation="vertical" >
<Button
android:id="@+id/rate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Rate us"
android:textColor="@color/black_font"
android:textSize="60sp" />
</RelativeLayout>
欲了解更多信息,请参阅this link
对于您的问题,您需要按 Density 创建它
ldpi 用于低密度 (ldpi) 屏幕 (~120dpi) 的资源。mdpi 中等密度 (mdpi) 屏幕 (~160dpi) 的资源。 (这是基线密度。)hdpi 用于高密度 (hdpi) 屏幕 (~240dpi) 的资源。xhdpi 超高密度 (xhdpi) 屏幕 (~320dpi) 的资源。nodpi 适用于所有密度的资源。这些是与密度无关的资源。无论当前屏幕的密度如何,系统都不会缩放带有此限定符标记的资源。tvdpi mdpi 和 hdpi 之间的屏幕资源;大约 213dpi。这不被视为“主要”密度组。它主要用于电视,大多数应用程序不需要它 - 为大多数应用程序提供 mdpi 和 hdpi 资源就足够了,系统将根据需要对其进行缩放。如果您认为有必要提供 tvdpi 资源,则应将它们的大小调整为 1.33*mdpi。例如,用于 mdpi 屏幕的 100px x 100px 图像对于 tvdpi 应该是 133px x 133px。【讨论】: