Layout Difference for activity

孤者浪人 提交于 2019-12-25 02:47:25

问题


I have created activity but both have different look.

Image of Nexsus 10

Image of 320 x 480 Image

At first image it shows too much spaces at bottom . how can I resolve that problem ? How do i make that responsive.

Thank you in advance


回答1:


Checkout this

Basically:

keep diffrent versions of your layout in folders in example

 layout-hdpi
 layout-mdpi 
 layout-other_selector_that_you_want

etc




回答2:


You will need to make the login page for both handset and tablet devices, and tweak the layouts accordingly.

The simplest case would be to have the layout for the smartphones stored in res/layout/login.xml and for the tablets in res/layout-large/login.xml Having these layouts separated, try to add some padding for the layout of tablet version and center the layout in the middle of the screen, I believe it will look much better.

(if you don't have the folder layout-large in res directory, you will need to create it manually)




回答3:


Well it seems you are wrapping height. If you are talking about ratios You should use weight in your layout instead of wrapping height.

Demo code

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
<TextView android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:text="Login"
    android:gravity="center"/>
<ImageView android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="2"
   android:src="@drawable/ic_launcher"
    android:gravity="center"/>
<EditText android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:hint="Enter User Name"/>
<EditText android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:hint="Enter Password"/>
<TextView android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="2"
    android:text="Large Text"
    android:gravity="center_vertical"/>
<Button android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:text="Login"/>
<View android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="1"/>
<LinearLayout android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:orientation="horizontal">
    <Button android:layout_width="0dip"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:text="Register"/>
    <Button android:layout_width="0dip"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:text="Help"/>
</LinearLayout>
<View android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="1"/>
</LinearLayout>


来源:https://stackoverflow.com/questions/21456207/layout-difference-for-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!