【问题标题】:Relative layout on different devices不同设备上的相对布局
【发布时间】:2015-01-27 17:22:03
【问题描述】:

我有一个应用程序,它应该适用于不同布局的手机和平板电脑。
在我的手机上它使用垂直布局并使用所有屏幕,而在我的平板电脑上它保持很小而不是使用整个屏幕。
我使用了相对布局,但参考了 fill_parent 的宽度,认为这是使用所有父级空间(整个屏幕)的正确方法。
这是我的代码:

 <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
        android:background="#bbbbbb" >

    <!-- Parte1  -->

    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:text="Distanza Km        m         Gare"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <Button
         android:id="@+id/button1"
         android:layout_width="wrap_content"
         android:layout_height="50dp"
         android:layout_alignParentLeft="true"
         android:layout_below="@+id/textView1"
         android:onClick="OnClickButton1"
         android:text="@string/calcola" />   

    <EditText
         android:id="@+id/editText1_1"
         android:layout_width="@dimen/single_textEdit"
         android:layout_height="50dp"
         android:layout_marginLeft="10dp"
         android:background="#fff123"        
         android:inputType="numberDecimal"
         android:singleLine="true"
         android:textSize="40sp" 
         android:gravity="center" 
         android:imeOptions="actionDone"
         android:layout_toRightOf="@+id/button1"
         android:nextFocusDown="@+id/editText1_2"
         android:layout_below="@+id/textView1"/>     

    <EditText
        android:id="@+id/editText1_2"
        android:layout_width="@dimen/double_textEdit"
        android:layout_height="50dp"
        android:layout_below="@+id/textView1"
        android:layout_marginLeft="10dp"
        android:background="#fff123"
        android:layout_toRightOf="@+id/editText1_1"        
        android:gravity="center"
        android:inputType="numberDecimal"
        android:nextFocusDown="@+id/editText2_1"
        android:singleLine="true"
        android:textSize="40sp" />

    <Spinner
        android:id="@+id/gare_spinner"
        android:layout_width="fill_parent"
        android:layout_below="@+id/textView1"
        android:layout_height="50dp"
        android:layout_marginLeft="10dp"
        android:background="@layout/border"
        android:gravity="center_vertical|center_horizontal"
        android:dropDownSelector="@drawable/ic_launcher"
        android:layout_toRightOf="@+id/editText1_2" />
        ....

【问题讨论】:

  • 创建另一个文件夹,res/layout-land 放置横向模式布局的位置。
  • 你能发一些图片让我们理解你的意思吗?
  • 你试过android:layout_weight吗?

标签: android android-layout android-relativelayout


【解决方案1】:

创建一个新的布局文件夹。您的普通文件夹仅称为 layout,但创建第二个称为 layout-sw600dp。这适用于 600 像素的屏幕宽度,因此基本上适用于平板电脑。您可以制作完全相同的 xml 布局,并在此处为它们提供不同的尺寸。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-30
    • 2020-06-13
    • 1970-01-01
    • 2012-11-22
    • 1970-01-01
    • 1970-01-01
    • 2017-06-06
    相关资源
    最近更新 更多