Android 虽然I';我用DP?
我正在制作这个简单的用户界面。它非常适合Nexus 5X(emulator)(1920x1080)。 但是当我在Galaxy Nexus(emulator)(1280x720)上运行应用程序时,UI似乎没有调整大小,这导致它不适合屏幕。如你所见,我只使用DP的尺寸。我做错了什么 Nexus 5X: 银河系连接: 我有以下代码:Android 虽然I';我用DP?,android,Android,我正在制作这个简单的用户界面。它非常适合Nexus 5X(emulator)(1920x1080)。 但是当我在Galaxy Nexus(emulator)(1280x720)上运行应用程序时,UI似乎没有调整大小,这导致它不适合屏幕。如你所见,我只使用DP的尺寸。我做错了什么 Nexus 5X: 银河系连接: 我有以下代码: <?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.CardView
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
style="@style/EditValues"
android:hint="num1"/>
<EditText
style="@style/EditValues"
android:hint="num2"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test123333333"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:orientation="horizontal"
android:paddingBottom="70dp">
<android.support.v7.widget.AppCompatButton
style="@style/OperatorButton"
android:text="+"/>
<android.support.v7.widget.AppCompatButton
style="@style/OperatorButton"
android:text="-"/>
<android.support.v7.widget.AppCompatButton
style="@style/OperatorButton"
android:text="*"/>
<android.support.v7.widget.AppCompatButton
style="@style/OperatorButton"
android:text="%"/>
</LinearLayout>
</LinearLayout>
@颜色/原色
@颜色/原色暗
@颜色/颜色重音
包装内容
包装内容
水平中心
50dp
100dp
100dp
@颜色/颜色重音
#fff
50dp
100dp显然将在更小的屏幕和更小的分辨率上占据更多的空间
这就是您需要在不同文件夹中使用不同值的地方,即
样式hdpi
,样式xhdpi
,样式xxhdpi
,100dp显然将在更小的屏幕上以更小的分辨率占据更大的空间
这就是您需要在不同文件夹中使用不同值的地方,即
样式hdpi
,样式xhdpi
,样式xxhdpi
,为不同的屏幕尺寸使用不同的尺寸
<style name="OperatorButton">
<item name="android:layout_width">@dimen/operator_btn_width</item>
<item name="android:layout_height">@dimen/operator_btn_height</item>
....
@尺寸/操作员宽度
@尺寸/操作员高度
....
然后创建附加值目录值ldpi、值hdpi、值xhdpi。。。
并添加不同值的dimens.xml文件,用于运算符\u btn\u width等
<resources>
<dimen name="activity_horizontal_margin">100dp</dimen>
<dimen name="activity_vertical_margin">100dp</dimen>
...
100dp
100dp
...
尺寸:对于不同的屏幕尺寸,使用不同的尺寸
<style name="OperatorButton">
<item name="android:layout_width">@dimen/operator_btn_width</item>
<item name="android:layout_height">@dimen/operator_btn_height</item>
....
@尺寸/操作员宽度
@尺寸/操作员高度
....
然后创建附加值目录值ldpi、值hdpi、值xhdpi。。。
并添加不同值的dimens.xml文件,用于运算符\u btn\u width等
<resources>
<dimen name="activity_horizontal_margin">100dp</dimen>
<dimen name="activity_vertical_margin">100dp</dimen>
...
100dp
100dp
...
维度:您误解了dp是什么。1 Dp为1/160英寸。它允许您确保一个项目在所有设备上具有相同的物理大小-例如,一个项目总是1英寸宽或总是有四分之一英寸的填充。但是如果一个屏幕更大,它显然比一个更小的屏幕有更多的dp。如果不合适的话,你需要为更小的设备使用不同的尺寸,甚至是完全不同的布局。你误解了dp是什么。1 Dp为1/160英寸。它允许您确保一个项目在所有设备上具有相同的物理大小-例如,一个项目总是1英寸宽或总是有四分之一英寸的填充。但是如果一个屏幕更大,它显然比一个更小的屏幕有更多的dp。如果不适合,您需要为较小的设备使用不同的尺寸甚至完全不同的布局。这不是dp的目的吗?它能适应每个屏幕吗?如果我需要为每一个dpi制作一个不同的,那么我就不能使用px吗?这不是dp的目的吗?它能适应每个屏幕吗?如果我需要为每个dpi制作一个不同的dpi,那么我就不能使用px吗?为什么不使用
android:weight
?为什么不使用android:weight
?