简体   繁体   中英

Layout not supporting in all screens

I am new to android , i am developing registration screen I have used scroll view to support in smaller screens, but when it comes to larger screens 7 inches layout is not fitting .

I don't know how to make this layout fit in all screens such that in small screens it should be scrollable I have searched in internet but it is of no use, so please help me on how to make my screen adaptable to all screens of android.` Here is the code i am using:

`

<LinearLayout
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="338dp"
    android:orientation="vertical"
    android:padding="20dp" >

    <EditText
        android:hint="@string/phoneno"
        android:id="@+id/usr_reg_et_phoneno"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/style_edittext"
        android:textAppearance="?android:attr/textAppearanceSmall" >
        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/usr_reg_et_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:ems="10"
        android:hint="@string/name"
        android:inputType="textPersonName"
        android:background="@drawable/style_edittext"
        android:textAppearance="?android:attr/textAppearanceSmall" >

    </EditText>

    <EditText
        android:id="@+id/usr_reg_et_email"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:ems="10"
        android:hint="@string/email"
        android:inputType="textEmailAddress"
        android:background="@drawable/style_edittext"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <EditText
        android:id="@+id/usr_reg_et_pwd"
        android:hint="@string/password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:ems="10"
        android:inputType="textPassword"
        android:background="@drawable/style_edittext"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="10dp"
        android:layout_weight="0.22" >

        <ToggleButton
            android:id="@+id/toggle_gender"
            android:layout_width="60dp"
            android:layout_height="40dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:background="@drawable/gender_check"
            android:focusable="false"
            android:focusableInTouchMode="false" 
            android:checked="true"/>

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/toggle_gender"
            android:layout_alignBottom="@+id/toggle_gender"
            android:layout_alignParentLeft="true"
            android:layout_marginLeft="18dp"
            android:text="@string/gender"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="#818080" />

        <ToggleButton
            android:layout_marginTop="8dp"
            android:id="@+id/toggle_user"
            android:layout_width="60dp"
            android:layout_height="40dp"
            android:layout_alignLeft="@+id/toggle_gender"
            android:layout_below="@+id/toggle_gender"
            android:background="@drawable/user_check"
            android:focusable="false"
            android:focusableInTouchMode="false" />

        <TextView
            android:id="@+id/login_et_phoneno"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/toggle_user"
            android:layout_alignBottom="@+id/toggle_user"
            android:layout_alignLeft="@+id/textView2"
            android:text="@string/role"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="#818080" />

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/textview1"
            android:layout_width="250dp"
            android:layout_height="100dp"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_margin="10dp"
            android:text="@string/tc"
            android:textAppearance="?android:attr/textAppearanceSmall" />

<ProgressBar
    android:id="@+id/progressBar1"
    android:visibility="gone"
    android:background="@drawable/radar"
    android:indeterminateDrawable="@drawable/progressbar3" 
    android:minHeight="48dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="100dp" />

<Button
    android:id="@+id/usr_reg_bt_register"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/textview1"
    android:layout_alignParentLeft="true"
    android:textColor="#ffffff"
    android:background="@drawable/style_button"
    android:text="@string/register" />

<TextView
    android:id="@+id/usr_reg_tv_tc"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/usr_reg_bt_register"
    android:layout_alignRight="@+id/textview1"
    android:layout_marginBottom="17dp"
    android:layout_marginRight="48dp"
    android:text="@string/tclink"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:textColor="#336600" />

    </RelativeLayout>
</LinearLayout>

`

Please refer these link:

http://developer.android.com/guide/practices/screens_support.html

For Different screen size, The following is a list of resource directories in an application that provides different layout designs for different screen sizes and different bitmap drawables for small, medium, high, and extra high density screens.You still need to edit the layout resource to fit better

res/layout/my_layout.xml             // layout for normal screen size ("default")
  res/layout-small/my_layout.xml       // layout for small screen size
  res/layout-large/my_layout.xml       // layout for large screen size
  res/layout-xlarge/my_layout.xml      // layout for extra large screen size
  res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation

  res/drawable-mdpi/my_icon.png        // bitmap for medium density
  res/drawable-hdpi/my_icon.png        // bitmap for high density
  res/drawable-xhdpi/my_icon.png       // bitmap for extra high density

The following code in the Manifest supports all dpis.

<supports-screens android:smallScreens="true" 
      android:normalScreens="true" 
      android:largeScreens="true"
      android:xlargeScreens="true"
      android:anyDensity="true" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM