了解Android屏幕分辨率&密度

时间:2012-12-21 23:33:21

标签: android android-layout screen-size

我一直在使用eeepad 10英寸平板电脑开发应用程序。它报告的屏幕尺寸为1280x752,密度为mdpi。

图片目前看起来像这样

tablet Screenshot

我最近买了一台Nexus 4(屏幕尺寸为1184 x 768,密度为xhdpi)。我假设如果我在手机上运行应用程序,它看起来会一样,只会更小。

我真正得到的是:

Phone Screenshot

不是我所期待的。

左侧列表视图的布局视图如下所示 -

        <?xml version="1.0" encoding="utf-8"?>
        <RelativeLayout  xmlns:tools="http://schemas.android.com/tools" android:orientation="horizontal"
            android:layout_width="match_parent" 
            android:layout_height="match_parent" 
            android:layout_marginRight="5dp"
            xmlns:android="http://schemas.android.com/apk/res/android">


                    <TextView android:id="@+id/tvName" 
                        android:gravity="center"
                        android:layout_width="80dp" 
                        android:layout_height="40dp" 
                        android:layout_marginLeft="10dp"
                        android:layout_marginRight="20dp"
                        android:layout_marginTop="5dp" 
                        android:text="XXX"
                        android:textSize="30sp"  
                        android:background="@drawable/rectanglesegment" 
                        android:textAppearance="?android:attr/textAppearanceMedium" />

                    <TextView android:id="@+id/tvLongName"
                        android:layout_toRightOf="@+id/tvName"
                        android:layout_width="wrap_content" 
                        android:layout_height="wrap_content" 
                        android:text="dfdfdsfdfdfdsfdsf" 
                        android:textAppearance="?android:attr/textAppearanceMedium" />

                    <TextView android:id="@+id/tvUsage" 
                        android:layout_below="@+id/tvLongName"
                        android:layout_toRightOf="@+id/tvName"
                        android:layout_height="wrap_content" 
                        android:layout_width="wrap_content"
                        android:layout_marginRight="5dp"
                        android:textColor="#ff0000"
                        android:gravity="right"
                        android:text="Required" 
                        android:textAppearance="?android:attr/textAppearanceMedium" />  

                    <TextView android:id="@+id/tvCardinality" 
                        android:layout_below="@+id/tvLongName"
                        android:layout_toRightOf="@+id/tvUsage"
                        android:layout_height="wrap_content" 
                        android:layout_width="wrap_content"
                        android:layout_alignParentRight="true" 
                        android:layout_marginRight="5dp"
                        android:layout_marginLeft="5dp"
                        android:text="(0..1)" 
                        android:textAppearance="?android:attr/textAppearanceMedium" />

        </RelativeLayout>

如何才能让手机上的布局更像平板电脑?

1 个答案:

答案 0 :(得分:2)

This最好从android开发者指南中解释多屏幕。特别是为xml使用大小限定符。如果您使用大型7英寸平板电脑。

相关问题