0

我有 3 个水平线性布局,我一直在 4.7 屏幕上制作 xml,看起来不错,然后我切换到更大的屏幕,看起来不太好。所以我的 xml 在 4.7 的屏幕尺寸上看起来不错,但在 10.01 和 7 上它
在 4.7 屏幕上搞砸了: 在此处输入图像描述

在 10,01 :在此处输入图像描述

<LinearLayout 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/backgroun"
    android:orientation="vertical" 
  >

 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="horizontal" >

     <Button
         android:id="@+id/button1"
         android:layout_width="wrap_content"
         android:layout_height="match_parent"
         android:layout_weight="1"
         android:text="Load" />

     <Button
         android:id="@+id/button2"
         android:layout_width="wrap_content"
        android:layout_height="match_parent"
         android:text="Play"
         android:layout_weight="1" />

     <Button
         android:id="@+id/button3"
         android:layout_width="wrap_content"
        android:layout_height="match_parent"
         android:text="Mute" 
         android:layout_weight="1"/>

     <Button
         android:id="@+id/button4"
         android:layout_width="wrap_content"
        android:layout_height="match_parent"
         android:text="Volume up"
         android:layout_weight="1" />

     <Button
         android:id="@+id/button5"
         android:layout_width="wrap_content"
         android:layout_height="match_parent"
         android:text="Volume up"
         android:layout_weight="1" />

     <Button
         android:id="@+id/button6"
         android:layout_width="wrap_content"
        android:layout_height="match_parent"
         android:text="Mute" 
         android:layout_weight="1"/>

     <Button
         android:id="@+id/button7"
         android:layout_width="wrap_content"
        android:layout_height="match_parent"
         android:text="Play"
         android:layout_weight="1"/>

     <Button
         android:id="@+id/button8"
         android:layout_width="wrap_content"
         android:layout_height="match_parent"
         android:text="Load"
         android:layout_weight="1" />

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="3"
        android:orientation="horizontal" >

        <SeekBar
            android:id="@+id/seekBar1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:layout_weight="7"/>

        <Button
            android:id="@+id/button9"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button" />

        <Button
            android:id="@+id/button10"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button" />

        <SeekBar
            android:id="@+id/seekBar2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
             android:layout_weight="7"/>

    </LinearLayout>
     <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal" >

         <SeekBar
             android:id="@+id/seekBar3"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_weight="1" />

         <SeekBar
             android:id="@+id/seekBar4"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_weight="1" />

    </LinearLayout>

    </LinearLayout>
4

2 回答 2

1

首先,当您使用时,android:layout_weight您应该设置android:layout_width="0dp"
除此之外,我建议为 xlarge 屏幕设置单独的布局。
这样做的方法是创建一个单独的文件夹,该文件夹将包含与原始布局同名的布局(例如 main.xml)。10" 屏幕的文件夹名称应该类似于layout-xlarge
有关更多详细信息,您应该在此处查看

于 2013-06-07T13:51:39.073 回答
1

适用于不同尺寸的屏幕。您还可以为更大的屏幕制作另一种布局。

res/layout-small
res/layout-large
res/layout-xlarge

创建一个名为“layout-xlarge”的新文件夹并将您的 xml 布局复制到其中,您可以调整大小。

Android 会自动为当前设备选择合适的布局。请记住,每个文件夹中的布局名称应该相同。

于 2013-06-07T13:58:22.873 回答