如何为多屏幕Android调整UI?

3

我有一个如下的XML文件。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:background="@drawable/imagesand"
    android:layout_height="match_parent" >
<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:orientation="vertical"
    android:paddingLeft="10dp"
    android:paddingRight="10dp" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Collaboration Set Up :"
        android:textSize="20dp" />

    <EditText
        android:id="@+id/projectname"
        android:layout_width="match_parent"
        android:layout_height="36dp"
        android:hint="Group Name"
        android:paddingLeft="10dp"
        android:background="@drawable/button"
        android:ems="10" >
    </EditText>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Data To Collect :"
        android:textSize="20dp" />

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

        <CheckBox
            android:id="@+id/fnamechk"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
             android:enabled="false"
            android:textSize="13dp"
            android:text=" First Name" />

        <CheckBox
            android:id="@+id/lnamechk"
             android:textSize="13dp"
            android:layout_width="wrap_content"
            android:checked="true"
             android:enabled="false"
            android:layout_height="wrap_content"
            android:text="Last Name" />

        <CheckBox
            android:id="@+id/personalemailchk"
            android:layout_width="wrap_content"
            android:checked="true"
            android:enabled="false"
            android:layout_height="wrap_content"
            android:text="Personal Email"
            android:textSize="13dp" />

    </LinearLayout>

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

        <CheckBox
            android:id="@+id/workphonechk"
             android:textSize="13dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Work Ph." />

        <CheckBox
            android:id="@+id/companychk"
            android:layout_width="wrap_content"

            android:layout_height="wrap_content"
            android:text="Company"

            android:textSize="13dp" />

        <CheckBox
            android:id="@+id/Workemailchk"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Work Email"
            android:textSize="13dp" />

    </LinearLayout>

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

        <CheckBox
            android:id="@+id/cellchk"
            android:layout_width="wrap_content"
            android:textSize="13dp"
            android:layout_height="wrap_content"
            android:text="MobNo." />

    </LinearLayout>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Data Visible to User:"
        android:textSize="20dp" />

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

        <CheckBox
            android:id="@+id/fname2"
            android:textSize="13dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:enabled="false"
            android:checked="true"
            android:text="First Name" />

        <CheckBox
            android:id="@+id/lname2"
            android:enabled="false"
            android:checked="true"
             android:textSize="13dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Last Name" />

        <CheckBox
            android:id="@+id/personalemail2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:enabled="false"
             android:checked="true"
            android:text="Personal Email"
            android:textSize="13dp" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingBottom="10dp" >

        <CheckBox
            android:id="@+id/workphone2"
             android:textSize="13dp"
            android:enabled="false"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Work Ph." />

        <CheckBox
            android:id="@+id/Comoany2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:enabled="false"

            android:text="Company"
            android:textSize="13dp" />

        <CheckBox
            android:id="@+id/workemail2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:enabled="false"
            android:text="Work Email"
            android:textSize="13dp" />

    </LinearLayout>

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

        <CheckBox
            android:id="@+id/cell2"
             android:textSize="13dp"
            android:enabled="false"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Mob.No" />

    </LinearLayout>

    <LinearLayout android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <RadioGroup
        android:id="@+id/radioGroup1"

        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <RadioButton
            android:id="@+id/available"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
         android:textSize="13dp"
            android:text="Available" />

        <RadioButton
            android:id="@+id/none"
            android:textSize="13dp"
            android:layout_gravity="center_horizontal"
            android:layout_width="wrap_content"
                android:layout_marginLeft="50dp"
            android:layout_height="wrap_content"
            android:text="None" />
    </RadioGroup>

    </LinearLayout>
     <LinearLayout android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <RadioGroup
        android:id="@+id/radioGroup2"
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <RadioButton
            android:id="@+id/Private"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
           android:textSize="13dp"
            android:text="Private" />

        <RadioButton
            android:id="@+id/Public"
              android:layout_marginLeft="65dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
           android:textSize="13dp"
            android:text="Public" />
    </RadioGroup>

    </LinearLayout>

    <Button
        android:id="@+id/generate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:background="@drawable/login"
        android:text="Generate" />

</LinearLayout>
</ScrollView>

当我在小型设备上打开它时,它看起来像这样。我已经实现了滚动视图。enter image description here 而当我在平板电脑上打开时,它看起来像这样。 enter image description here 正如您所看到的,在制表符中浪费了更多的空间,那么我可以利用免费空间,并根据屏幕尺寸使复选框扩展到整个屏幕吗?
4个回答

4

为此,您需要使用配置限定符(Configuration Qualifiers),您可以参考以下帖子:

1.帖子A 2.帖子B

基本上,您的项目应该如下所示:

enter image description here

或者,您也可以通过尺寸控制布局,例如:

<Button android:width= "@dimen/somewidth"/>

像这样为多个值声明此维度:

enter image description here


如何在dimen中声明ems? - AZ_

1

根据您的设备,您需要将不同的图像放置在不同的drawable文件夹中。边距和填充不直接在xml文件中声明,而是在dimens.xml文件中声明,然后使用它。这个dimens.xml文件是基于设备特定的,所以请检查一下。如果有任何疑问,请告诉我。

查看更多细节


1
你应该添加一些参考链接以便更好地理解。 - Chintan Khetiya
请查看此官方链接... http://developer.android.com/guide/practices/screens_support.html#overview 希望对您有所帮助。@chintan - dipali
我的意思是你应该在你的答案中添加这个链接。 - Chintan Khetiya

0

我看到你每次想要一个多选框时都使用多个标签来定义。

我曾经遇到过这个问题,但我找到了解决方法,那就是动态定义元素,也就是使用Java代码。

这个LINK 解决了我的问题。 页面中给出的函数定义了一种在特定设备的最大宽度达到时创建新线性布局的方法。

我还想建议不要在XML文件中使用太多代码来定义复选框。这将导致应用程序的大小增加。然而,如果您可以在字符串中定义复选框的名称,然后在Java代码中循环遍历它们以创建复选框,apk文件将更小,更容易下载给用户。

希望这能帮到你。


0
除了已经给出的答案之外,我们可以在dimens.xml中像这样添加ems: 3

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接