我有一个 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>
当我在较小的设备上打开它时,它看起来像这样。我已经实现了 ScrollView 。
当我在平板电脑中打开时,它看起来像这样。
如您所见,在选项卡中浪费了较大的空间,那么我可以利用可用空间并根据屏幕尺寸使复选框分布在屏幕上吗?
最佳答案
为此您必须使用Configuration Qualifiers
,您可以引用以下帖子:
基本上你的元素应该是这样的:
或者,您也可以通过维度来控制布局,例如:
<Button android:width= "@dimen/somewidth"/>
像这样为多个值声明此维度:
关于android - 如何为多屏android调整用户界面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20834995/