我是android新手。我创建了一个简单的示例来测试Nexus One和Galaxy Nexus上Android的缩放功能。
这是我的布局:
<RelativeLayout 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:background="@drawable/sfondo"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.testlayout.MainActivity$PlaceholderFragment" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="30dp"
android:layout_marginTop="22dp"
android:text="@string/hello_world" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_marginLeft="16dp"
android:layout_marginTop="75dp"
android:layout_toRightOf="@+id/textView1"
android:text="@string/hello_world" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_centerVertical="true"
android:text="@string/hello_world" />
</RelativeLayout>
使用具有特定文本位置的特定背景图像,我认为文本位置在一台设备中正确,而在另一台设备中不正确。
这两款手机属于同一布局类别:正常。
为什么我会得到两个不同的结果?(也使用dp)如何在两个设备上获得相同的结果?谢谢
使用dp可以确保视图和边距的物理大小在所有设备上都相同。
这意味着,如果您使用填充整个屏幕的背景图像,并且设备的屏幕尺寸不同,则每个设备的“视图”图像上的位置将有所不同。
小例子:
拍摄一个10厘米,160 dp的屏幕。在dp中使用页边距,这实际上会导致1厘米页边距(屏幕的10%)。
现在拿一个20厘米的屏幕,160dp。在dp中具有相同的边距时,通常它仍为1cm,但这仅是屏幕的5%。但是背景的实际尺寸将是10厘米屏幕尺寸的两倍,因此将关闭位置。
解决此问题的一种方法是在代码中进行定位,因此您可以根据屏幕的可用像素来缩放,但是通常我不建议您使用需要在其上绝对定位Views的背景图像。 。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句