不同屏幕的布局调整大小问题

时间:2016-09-14 05:25:03

标签: android android-layout

我想根据可用的屏幕尺寸调整应用程序的布局,但无法实现相同的效果。我为横向和纵向模式制作了两个布局,但其内容(编辑文本)包含在线性布局中并未根据屏幕调整大小。

以下是我的布局:

Activity_Login(人像):

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context="com.prosares.intralive.LoginActivity2">


<LinearLayout
    android:id="@+id/lin_all"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:orientation="vertical"
    android:layout_gravity="center">



<ImageView
    android:id="@+id/background"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:adjustViewBounds="true"
    android:scaleType="centerCrop"
    android:src="@drawable/login"

    />


</LinearLayout>



<LinearLayout
    android:id="@+id/lin_all1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
   >

<EditText
    android:layout_width="wrap_content"
    android:inputType="textPersonName"
    android:hint="Username"
    android:layout_height="wrap_content"
    android:ems="10"
    android:background="@drawable/eventpopuprect"
    android:drawableLeft="@drawable/username"
    android:id="@+id/editText"
    android:layout_weight="1"
    android:text=""
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:layout_gravity="center"/>

<EditText
    android:layout_width="wrap_content"
    android:inputType="textPassword"
    android:layout_height="wrap_content"
    android:ems="10"
    android:layout_weight="1"
    android:layout_marginTop="10dp"
    android:background="@drawable/eventpopuprect"
    android:drawableLeft="@drawable/password"
    android:id="@+id/editText2"
    android:layout_below="@+id/editText"
    android:layout_alignLeft="@+id/editText"
    android:layout_alignStart="@+id/editText"
    android:hint="password"
    android:text=""
    android:layout_alignRight="@+id/editText"
    android:layout_alignEnd="@+id/editText"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:layout_gravity="center"/>

<ImageButton
    android:layout_width="80dp"
    android:layout_height="30dp"
    android:id="@+id/imageButtonLogin"
    android:layout_marginTop="10dp"
    android:background="@drawable/login_button"
    android:layout_below="@+id/editText2"
    android:layout_alignRight="@+id/editText2"
    android:layout_alignEnd="@+id/editText2"
    android:layout_gravity="right"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true" />

</LinearLayout>

Activity_Login(横向):

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="com.prosares.intralive.LoginActivity2"
android:orientation="vertical">


<LinearLayout
    android:id="@+id/lin_all"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:orientation="vertical">

<ImageView
    android:id="@+id/background"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:adjustViewBounds="true"
    android:scaleType="centerCrop"
    android:src="@drawable/login"

    />

<LinearLayout
    android:id="@+id/lin_all1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:orientation="vertical">

<EditText
    android:layout_width="wrap_content"
    android:layout_marginTop="10dp"
    android:inputType="textPersonName"
    android:hint="Username"
    android:layout_height="wrap_content"
    android:ems="10"
    android:background="@drawable/eventpopuprect"
    android:drawableLeft="@drawable/username"
    android:id="@+id/editText"
    android:text=""
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true" />

<EditText
    android:layout_width="wrap_content"
    android:inputType="textPassword"
    android:layout_height="wrap_content"
    android:ems="10"
    android:layout_marginTop="10dp"
    android:background="@drawable/eventpopuprect"
    android:drawableLeft="@drawable/password"
    android:id="@+id/editText2"
    android:layout_below="@+id/editText"
    android:layout_alignLeft="@+id/editText"
    android:layout_alignStart="@+id/editText"
    android:hint="password"
    android:text=""
    android:layout_alignRight="@+id/editText"
    android:layout_alignEnd="@+id/editText"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"/>

<ImageButton
    android:layout_width="80dp"
    android:layout_height="30dp"
    android:id="@+id/imageButtonLogin"
    android:layout_marginTop="10dp"
    android:background="@drawable/login_button"
    android:layout_below="@+id/editText2"
    android:layout_alignRight="@+id/editText2"
    android:layout_alignEnd="@+id/editText2"
    android:layout_gravity="right" />
</LinearLayout>

1 个答案:

答案 0 :(得分:5)

您已将宽度和高度设置为wrap_content。在不同屏幕尺寸的不同值文件夹的帮助下,给出静态高度。在不同的文件中,您必须使用不同的值给出相同的维名称。

res/values/dimens.xml(default)
res/values-ldpi/dimens.xml   (240x320 and nearer resolution)
res/values-mdpi/dimens.xml   (320x480 and nearer resolution)
res/values-hdpi/dimens.xml   (480x800, 540x960 and nearer resolution)
res/values-xhdpi/dimens.xml  (720x1280 - Samsung S3, Micromax Canvas HD, etc) 
res/values-xxhdpi/dimens.xml (1080x1920 - Samsung S4, HTC one, etc)
res/values-large/dimens.xml  (480x800)

res/values-large-mdpi/dimens.xml (600x1024)
res/values-sw600dp/dimens.xml  (600x1024)
res/values-sw720dp/dimens.xml  (800x1280)
res/values-xlarge-xhdpi/dimens.xml (2560x1600 - Nexus 10")
res/values-large-xhdpi/dimens.xml  (1200x1920 - Nexus 7"(latest))
相关问题