【问题标题】:different layouts for multiple screens多个屏幕的不同布局
【发布时间】:2014-11-29 14:41:23
【问题描述】:

我已经为多个屏幕创建了不同的文件夹..

res/layout(用于普通屏幕) res/layout-large(用于大屏幕) res/layout-xlarge(用于 xhdpi 屏幕)

当我在 xhdpi 的 Grand 2 手机上进行测试时,它会从 res/layout 文件夹中获取值...

这是处理多屏幕布局的正确方法...我必须在 Android.manifest 文件中进行 ant 更改吗?请帮助我..提前谢谢..我已经将滚动条大小更改为两个不同的布局...

res/layout/main.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/back1">
    <ScrollView
    android:layout_width="match_parent"
    android:layout_height="200dp"


    android:scrollbars="horizontal" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >



    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="33dp"
        android:layout_marginTop="2dp"
        android:text=""
        android:textColor="#FFFFFF" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="33dp"
        android:text=""
        android:textColor="#FFFFFF" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="33dp"
        android:text=""
        android:textColor="#FFFFFF" />

    <TextView
        android:id="@+id/textView5"
        android:layout_width="264dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="10dp"
        android:text=""
        android:textColor="#FFFFFF" />


        <TableLayout
            android:id="@+id/maintable"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="20dp" >
        </TableLayout>




        <TableLayout
            android:id="@+id/maintable1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="10dp" >
        </TableLayout>

    <TextView
        android:id="@+id/textView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@android:id/list"
        android:text=""
        android:textColor="#FFFFFF" />

    <ListView
        android:id="@android:id/list"
        style=" android:listViewStyle"
        android:layout_width="fill_parent"
        android:layout_height="70dp"
        android:layout_below="@+id/textView6"
        android:layout_marginLeft="33dp"
        android:drawSelectorOnTop="true"
        android:textColor="#FFFFFF" >

    </ListView>
     </LinearLayout>

</ScrollView>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="0dp"

    android:orientation="horizontal"
      >
    <TextView
        android:id="@+id/textView8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="7dp"
        android:layout_gravity="bottom"
        android:text=""
        android:layout_marginBottom="5dp"
        android:textColor="#FFFFFF"
        android:textColorLink="#FFFFFF" />

    <TextView
        android:id="@+id/textView7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="12dp"
        android:layout_marginTop="1dp"
        android:layout_marginBottom="5dp"
        android:text=""
        android:layout_gravity="bottom"
        android:textColor="#FFFFFF"
        android:textColorLink="#FFFFFF" />
    </LinearLayout>
    </RelativeLayout>

res/layout-xlarge

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/back1">
    <ScrollView
    android:layout_width="match_parent"
    android:layout_height="400dp"


    android:scrollbars="horizontal" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >



    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="33dp"
        android:layout_marginTop="2dp"
        android:text=""
        android:textColor="#FFFFFF" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="33dp"
        android:text=""
        android:textColor="#FFFFFF" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="33dp"
        android:text=""
        android:textColor="#FFFFFF" />

    <TextView
        android:id="@+id/textView5"
        android:layout_width="264dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="10dp"
        android:text=""
        android:textColor="#FFFFFF" />


        <TableLayout
            android:id="@+id/maintable"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="20dp" >
        </TableLayout>




        <TableLayout
            android:id="@+id/maintable1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="10dp" >
        </TableLayout>

    <TextView
        android:id="@+id/textView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@android:id/list"
        android:text=""
        android:textColor="#FFFFFF" />

    <ListView
        android:id="@android:id/list"
        style=" android:listViewStyle"
        android:layout_width="fill_parent"
        android:layout_height="70dp"
        android:layout_below="@+id/textView6"
        android:layout_marginLeft="33dp"
        android:drawSelectorOnTop="true"
        android:textColor="#FFFFFF" >

    </ListView>
     </LinearLayout>

</ScrollView>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="0dp"

    android:orientation="horizontal"
      >
    <TextView
        android:id="@+id/textView8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="7dp"
        android:layout_gravity="bottom"
        android:text=""
        android:layout_marginBottom="5dp"
        android:textColor="#FFFFFF"
        android:textColorLink="#FFFFFF" />

    <TextView
        android:id="@+id/textView7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="12dp"
        android:layout_marginTop="1dp"
        android:layout_marginBottom="5dp"
        android:text=""
        android:layout_gravity="bottom"
        android:textColor="#FFFFFF"
        android:textColorLink="#FFFFFF" />
    </LinearLayout>
    </RelativeLayout>

【问题讨论】:

标签: android android-layout


【解决方案1】:

您说“res/layout-xlarge(用于 xhdpi 屏幕)”是错误的。如果你想根据密度制作不同的布局,你应该使用 hdpi、xhdpi、xxhdpi 和 xxxhdpi 修饰符:

...
res/layout-hdpi ---> for HDPI screens.
res/layout-xxdpi ---> for XHDPI screens.
res/layout-xxhdpi ---> for XXHDPI screens.
...

使用了 large 和 xlarge 修饰符(自 Android 3.2 起,它们已被弃用,这意味着您应该使用上述修饰符)根据设备的大小对设备进行分组。

更多信息http://developer.android.com/guide/practices/screens_support.html

【讨论】:

    【解决方案2】:

    尝试布局文件夹,如:

    layout             // layout for normal screen size ("default")
    layout-large       // layout for large screen size
    layout-xlarge      // layout for extra-large screen size
    layout-xlarge-land // layout for extra-large in landscape orientation
    

    在 AndroidManifest.xml 中添加支持屏幕:

    <supports-screens android:resizeable=["true"| "false"]
              android:smallScreens=["true" | "false"]
              android:normalScreens=["true" | "false"]
              android:largeScreens=["true" | "false"]
              android:xlargeScreens=["true" | "false"]
              android:anyDensity=["true" | "false"]
              android:requiresSmallestWidthDp="integer"
              android:compatibleWidthLimitDp="integer"
              android:largestWidthLimitDp="integer"/>
    

    参考。 :http://developer.android.com/guide/practices/screens_support.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多