不使用drawable时调整视图的高度

时间:2016-09-01 09:05:27

标签: android android-layout

我正在制作一个简单的登录屏幕,如下所示:

login image

上面的截图是在4.7"屏幕尺寸

以及以下屏幕截图拍摄于5.5"屏幕尺寸:

same login image

此屏幕没有使用图像,因此没有机会使用hdpi,mdpi,xhdpi。 只是一个简单的编辑文本和文本视图和按钮。

我想在两种屏幕尺寸中显示相同的屏幕。 谁可以帮我这个? 我该怎么做?

以下是xml:

<?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".LoginActivity">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/White"
    android:gravity="center"
    android:titleTextColor="@color/loginColorPrimary"
    app:title="Login"
    app:titleTextAppearance="@style/Toolbar.TitleText" />

<ScrollView
    android:layout_below="@id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <RelativeLayout
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/White">

        <EditText
            android:id="@+id/et_login_email_id"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/activity_horizontal_margin"
            android:background="@drawable/et_login_rect_shape"
            android:hint="@string/et_login_email_hint"
            android:inputType="textEmailAddress"
            android:padding="@dimen/et_login_padding"
            android:textColor="@color/Black"
            android:textColorHint="@color/loginEditTextHintColor"
            android:textSize="@dimen/et_login_text_size" />

        <EditText
            android:id="@+id/et_login_mobile"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/et_login_email_id"
            android:layout_margin="@dimen/activity_horizontal_margin"
            android:background="@drawable/et_login_rect_shape"
            android:hint="@string/et_login_mobile_hint"
            android:inputType="number"
            android:padding="@dimen/et_login_padding"
            android:textColor="@color/Black"
            android:textColorHint="@color/loginEditTextHintColor"
            android:textSize="@dimen/et_login_text_size" />

        <Button
            android:id="@+id/btn_login"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/et_login_mobile"
            android:layout_margin="@dimen/activity_horizontal_margin"
            android:background="@drawable/btn_rounded_red"
            android:text="Login"
            android:textAllCaps="false"
            android:textColor="@color/White"
            android:textSize="@dimen/btn_login_text_size" />


        <TextView
            android:id="@+id/tv_login_forgot_pw"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/btn_login"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginRight="@dimen/activity_horizontal_margin"
            android:gravity="center"
            android:text="@string/tvLoginForgotPassword"
            android:textColor="@color/tvLoginForgotPw"
            android:textSize="@dimen/tv_login_text_size" />

        <TextView
            android:id="@+id/tv_login_or"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/tv_login_forgot_pw"
            android:layout_marginBottom="18dp"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginRight="@dimen/activity_horizontal_margin"
            android:layout_marginTop="18dp"
            android:gravity="center"
            android:text="Or"
            android:textColor="@color/tvLoginColor"
            android:textSize="@dimen/tv_login_or_text_size" />

        <Button
            android:id="@+id/btn_facebook"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/tv_login_or"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginRight="@dimen/activity_horizontal_margin"
            android:background="@color/btnLoginWithFacebook"
            android:text="Login with Facebook"
            android:textAllCaps="false"
            android:textColor="@color/White"
            android:textSize="@dimen/btn_login_text_size" />

        <Button
            android:id="@+id/btn_Google"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/btn_facebook"
            android:layout_margin="@dimen/activity_horizontal_margin"
            android:background="@color/btnLoginWithGoogle"
            android:text="Login with google+"
            android:textAllCaps="false"
            android:textColor="@color/White"
            android:textSize="@dimen/btn_login_text_size" />

        <TextView
            android:id="@+id/tv_login_do_not_account"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/btn_Google"
            android:layout_margin="@dimen/activity_horizontal_margin"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginRight="@dimen/activity_horizontal_margin"
            android:gravity="center"
            android:text="Do not have an account? Register!"
            android:textColor="@color/tvLoginColor"
            android:textSize="@dimen/tv_login_text_size" />

        <LinearLayout
            android:id="@+id/layout_for_btn_buyers_sellers"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/tv_login_do_not_account"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginRight="@dimen/activity_horizontal_margin"
            android:orientation="horizontal">

            <Button
                android:id="@+id/btn_one"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginRight="16dp"
                android:layout_weight="1"
                android:background="@drawable/btn_login_background_rect_shape"
                android:padding="0dp"
                android:text="Button ONE"
                android:textAllCaps="false"
                android:textColor="@color/tvLoginColor"
                android:textSize="@dimen/btn_login_text_size" />

            <Button
                android:id="@+id/btn_two"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="16dp"
                android:layout_weight="1"
                android:background="@drawable/btn_login_background_rect_shape"
                android:padding="0dp"
                android:text="Button TWO"
                android:textAllCaps="false"
                android:textColor="@color/tvLoginColor"
                android:textSize="@dimen/btn_login_text_size" />

        </LinearLayout>
    </RelativeLayout>
</ScrollView>

2 个答案:

答案 0 :(得分:0)

使用重量概念并使高度为0dp,以便根据屏幕高度扩展和压缩布局高度。

答案 1 :(得分:0)

By using weight concept 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="8"
        android:orientation="vertical">

        <EditText
            android:id="@+id/et_login_email_id"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_margin="@dimen/activity_horizontal_margin"
            android:layout_weight="1"
            android:hint="Enter Email id"
            android:inputType="textEmailAddress"
            android:textColor="@color/Black"
            android:textColorHint="@color/loginEditTextHintColor"
            android:textSize="16dp" />

        <EditText
            android:id="@+id/et_login_mobile"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_below="@id/et_login_email_id"
            android:layout_margin="@dimen/activity_horizontal_margin"
            android:layout_weight="1"
            android:hint="Enter mobile number"
            android:inputType="number"
            android:textColor="@color/Black"
            android:textColorHint="@color/loginEditTextHintColor"
            android:textSize="16sp" />


        <Button
            android:id="@+id/btn_login"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_below="@id/et_login_mobile"
            android:layout_margin="@dimen/activity_horizontal_margin"
            android:layout_weight="1"
            android:background="@color/btn_rounded_red"
            android:text="Login"
            android:textAllCaps="false"
            android:textColor="@color/White"
            android:textSize="20dp" />


        <TextView
            android:id="@+id/tv_login_forgot_pw"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_below="@id/btn_login"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginRight="@dimen/activity_horizontal_margin"
            android:layout_weight="1"
            android:gravity="center"
            android:text="forgot password"
            android:textColor="#87D1ED"
            android:textSize="20dp" />


        <TextView
            android:id="@+id/tv_login_or"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_below="@id/tv_login_forgot_pw"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginRight="@dimen/activity_horizontal_margin"
            android:layout_weight="1"
            android:gravity="center"
            android:text="Or"
            android:textColor="#434343"
            android:textSize="22dp" />

        <Button
            android:id="@+id/btn_facebook"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_below="@id/tv_login_or"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginRight="@dimen/activity_horizontal_margin"
            android:layout_weight="1"
            android:background="#3C5899"
            android:text="Login with Facebook"
            android:textAllCaps="false"
            android:textColor="@color/White"
            android:textSize="20dp" />


        <Button
            android:id="@+id/btn_Google"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_below="@id/btn_facebook"
            android:layout_margin="@dimen/activity_horizontal_margin"
            android:layout_weight="1"
            android:background="#C52C2E"
            android:text="Login with google+"
            android:textAllCaps="false"
            android:textColor="@color/White"
            android:textSize="20dp" />

        <TextView
            android:id="@+id/tv_login_do_not_account"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_below="@id/btn_Google"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginRight="@dimen/activity_horizontal_margin"
            android:layout_weight="1"
            android:gravity="center"
            android:text="Do not have an account? Register!"
            android:textColor="#A6A6A6"
            android:textSize="20dp" />


        <LinearLayout
            android:id="@+id/layout_for_btn_buyers_sellers"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginRight="@dimen/activity_horizontal_margin"
            android:layout_weight="1"
            android:orientation="horizontal">

            <Button
                android:id="@+id/btn_one"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginRight="16dp"
                android:layout_weight="1"
                android:padding="0dp"
                android:text="Button ONE"
                android:textAllCaps="false"
                android:textColor="#A6A6A6"
                android:textSize="20dp" />

            <Button
                android:id="@+id/btn_two"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="16dp"
                android:layout_weight="1"
                android:padding="0dp"
                android:text="Button TWO"
                android:textAllCaps="false"
                android:textColor="#A6A6A6"
                android:textSize="20dp" />

        </LinearLayout>


    </LinearLayout>


</LinearLayout>