Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to adjust UI for multiple screen android?

I have a xml file as follows.

<?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>

when I open this in smaller devices it looks like this. I have implemented scroll view. enter image description here

and when I open in tablet it lokks like this.

enter image description here

As you can see, in tab larger space is wasted, So can I utilize the free space and make the check boxes spread over the screen depending on the screen size?

like image 823
user2699728 Avatar asked Nov 29 '25 19:11

user2699728


1 Answers

You have to use Configuration Qualifiers for this, you can refer to the following post:

1.Post A 2.Post B

Basically your project should look like this:

enter image description here

Or, you could also control the layout through dimensions, like for example:

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

Declare this dimen for multiple values like this:

enter image description here

like image 102
Rakeeb Rajbhandari Avatar answered Dec 02 '25 08:12

Rakeeb Rajbhandari



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!