简体   繁体   English

如何在另一个布局之上添加布局?

[英]How to add Layout on top of another Layout?

My English is poor. 我的英文程度不高。 So I threw off the video. 所以我取消了录像。 I think any programmer looking at this will understand the reason. 我认为任何程序员对此都会有所了解。 Thank you in advance 先感谢您

I want to learn how to use ReleaseativeLayout correctly, because ConstainLayout is very buggy. 我想学习如何正确使用ReleaseativeLayout,因为ConstainLayout有很多问题。 Even using it in Android Studio Canary. 即使在Android Studio Canary中使用它。

So I'm using ReleativeLayout and LineartLayout now. 所以我现在使用ReleativeLayout和LineartLayout。 These are the most effective ViewGroup. 这些是最有效的ViewGroup。 I thought. 我想。 But it turned out all wrong 但事实证明一切错

在此处输入图片说明


XML Code XML代码

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:theme="@style/ThemeOverlay.AppCompat.Dark"
    android:background="@drawable/login_faggot">

    <TextView
        android:gravity="center_horizontal"
        android:layout_above="@+id/plsLogin"
        android:text="Welcome."
        android:textSize="18sp"
        android:textColor="@color/white"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    <TextView
        android:layout_marginBottom="25dp"
        android:textSize="16sp"
        android:textColor="@color/grayBg"
        android:gravity="center_horizontal"
        android:id="@+id/plsLogin"
        android:layout_above="@+id/editLogin"
        android:text="Please Login."
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <TextView
        android:background="@color/white"
        android:layout_alignLeft="@+id/editLogin"
        android:layout_alignBaseline="@+id/editLogin"
        android:layout_marginStart="50dp"
        android:layout_width="1dp"
        android:layout_height="wrap_content"/>
    <TextView
        android:background="@color/white"
        android:layout_alignLeft="@+id/editPass"
        android:layout_alignBaseline="@+id/editPass"
        android:layout_marginStart="50dp"
        android:layout_width="1dp"
        android:layout_height="wrap_content"/>
    <EditText
        android:paddingStart="20dp"
        android:drawableStart="@drawable/ic_mail_white_24dp"
        android:drawablePadding="15dp"
        android:hint="@string/user_name"
        android:layout_alignStart="@+id/buttonLogin"
        android:layout_alignEnd="@+id/buttonLogin"
        android:layout_above="@+id/editPass"
        android:id="@+id/editLogin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    <EditText
        android:drawableStart="@drawable/ic_lock_white_24dp"
        android:paddingStart="20dp"
        android:drawablePadding="15dp"
        android:hint="@string/password"
        android:layout_alignEnd="@+id/buttonLogin"
        android:layout_alignStart="@+id/buttonLogin"
        android:layout_above="@+id/linearLayout"
        android:id="@+id/editPass"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <LinearLayout
        android:layout_marginStart="15dp"
        android:id="@+id/linearLayout"
        android:layout_above="@+id/buttonLogin"
        android:layout_alignEnd="@+id/buttonLogin"
        android:layout_alignStart="@+id/buttonLogin"
        android:layout_width="match_parent"
        android:layout_marginBottom="50dp"
        android:layout_height="wrap_content">
        <CheckBox
            style="@style/Widget.AppCompat.CompoundButton.RadioButton"
            android:id="@+id/radioButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Remember Me"
            android:paddingStart="15dp"
            android:textColor="@color/white"/>

        <TextView
            android:visibility="invisible"
            android:id="@+id/textView"
            android:textColor="@color/white"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="end"
            android:text="Forgot Password"/>
    </LinearLayout>

    <android.support.v7.widget.AppCompatButton
        android:id="@+id/buttonLogin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginEnd="30dp"
        android:layout_marginStart="30dp"
        android:background="@drawable/button_round_corner"
        app:backgroundTint="@color/colorOrangeUsSite"
        android:text="@string/login"
        android:textColor="@color/white"/>

    <FrameLayout
        android:background="@color/black"
        android:alpha="0.8"
        android:visibility="gone"
        android:id="@+id/layoutProgressBar"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ProgressBar
            android:theme="@style/ProgressBar"
            android:layout_gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    </FrameLayout>
</RelativeLayout>

Just add one more Relative Layout below of your parent layout and set Gravity to it 只需在父布局的下方添加一个相对布局 ,然后将Gravity设置为它

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
android:background="@drawable/login_faggot">

<RelativeLayout
    android:layout_width="match_parent"
    android:gravity="center"
    android:layout_height="match_parent">

<TextView
    android:gravity="center_horizontal"
    android:layout_above="@+id/plsLogin"
    android:text="Welcome."
    android:textSize="18sp"
    android:textColor="@color/white"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>
<TextView
    android:layout_marginBottom="25dp"
    android:textSize="16sp"
    android:textColor="@color/grayBg"
    android:gravity="center_horizontal"
    android:id="@+id/plsLogin"
    android:layout_above="@+id/editLogin"
    android:text="Please Login."
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

<TextView
    android:background="@color/white"
    android:layout_alignLeft="@+id/editLogin"
    android:layout_alignBaseline="@+id/editLogin"
    android:layout_marginStart="50dp"
    android:layout_width="1dp"
    android:layout_height="wrap_content"/>
<TextView
    android:background="@color/white"
    android:layout_alignLeft="@+id/editPass"
    android:layout_alignBaseline="@+id/editPass"
    android:layout_marginStart="50dp"
    android:layout_width="1dp"
    android:layout_height="wrap_content"/>
<EditText
    android:paddingStart="20dp"
    android:drawableStart="@drawable/ic_mail_white_24dp"
    android:drawablePadding="15dp"
    android:hint="@string/user_name"
    android:layout_alignStart="@+id/buttonLogin"
    android:layout_alignEnd="@+id/buttonLogin"
    android:layout_above="@+id/editPass"
    android:id="@+id/editLogin"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>
<EditText
    android:drawableStart="@drawable/ic_lock_white_24dp"
    android:paddingStart="20dp"
    android:drawablePadding="15dp"
    android:hint="@string/password"
    android:layout_alignEnd="@+id/buttonLogin"
    android:layout_alignStart="@+id/buttonLogin"
    android:layout_above="@+id/linearLayout"
    android:id="@+id/editPass"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

<LinearLayout
    android:layout_marginStart="15dp"
    android:id="@+id/linearLayout"
    android:layout_above="@+id/buttonLogin"
    android:layout_alignEnd="@+id/buttonLogin"
    android:layout_alignStart="@+id/buttonLogin"
    android:layout_width="match_parent"
    android:layout_marginBottom="50dp"
    android:layout_height="wrap_content">
    <CheckBox
        style="@style/Widget.AppCompat.CompoundButton.RadioButton"
        android:id="@+id/radioButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Remember Me"
        android:paddingStart="15dp"
        android:textColor="@color/white"/>

    <TextView
        android:visibility="invisible"
        android:id="@+id/textView"
        android:textColor="@color/white"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="end"
        android:text="Forgot Password"/>
</LinearLayout>

<android.support.v7.widget.AppCompatButton
    android:id="@+id/buttonLogin"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginEnd="30dp"
    android:layout_marginStart="30dp"
    android:background="@drawable/button_round_corner"
    app:backgroundTint="@color/colorOrangeUsSite"
    android:text="@string/login"
    android:textColor="@color/white"/>

</RelativeLayout>

<FrameLayout
    android:background="@color/black"
    android:alpha="0.8"
    android:visibility="gone"
    android:id="@+id/layoutProgressBar"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ProgressBar
        android:theme="@style/ProgressBar"
        android:layout_gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</FrameLayout>

  1. Only parent layout height and width would match parent instead of a child. 仅父布局的高度和宽度将匹配父而不是子。
  2. you've have entered FrameLayout height="match_parent" 您已经输入了FrameLayout height =“ match_parent”
  3. you've to implement like this. 您必须像这样实现。

      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:theme="@style/ThemeOverlay.AppCompat.Dark" android:background="@drawable/login_faggot"> <TextView android:gravity="center_horizontal" android:layout_above="@+id/plsLogin" android:text="Welcome." android:textSize="18sp" android:textColor="@color/white" android:layout_width="match_parent" android:layout_height="wrap_content"/> <TextView android:layout_marginBottom="25dp" android:textSize="16sp" android:textColor="@color/grayBg" android:gravity="center_horizontal" android:id="@+id/plsLogin" android:layout_above="@+id/editLogin" android:text="Please Login." android:layout_width="match_parent" android:layout_height="wrap_content"/> <TextView android:background="@color/white" android:layout_alignLeft="@+id/editLogin" android:layout_alignBaseline="@+id/editLogin" android:layout_marginStart="50dp" android:layout_width="1dp" android:layout_height="wrap_content"/> <TextView android:background="@color/white" android:layout_alignLeft="@+id/editPass" android:layout_alignBaseline="@+id/editPass" android:layout_marginStart="50dp" android:layout_width="1dp" android:layout_height="wrap_content"/> <EditText android:paddingStart="20dp" android:drawableStart="@drawable/ic_mail_white_24dp" android:drawablePadding="15dp" android:hint="@string/user_name" android:layout_alignStart="@+id/buttonLogin" android:layout_alignEnd="@+id/buttonLogin" android:layout_above="@+id/editPass" android:id="@+id/editLogin" android:layout_width="match_parent" android:layout_height="wrap_content"/> <EditText android:drawableStart="@drawable/ic_lock_white_24dp" android:paddingStart="20dp" android:drawablePadding="15dp" android:hint="@string/password" android:layout_alignEnd="@+id/buttonLogin" android:layout_alignStart="@+id/buttonLogin" android:layout_above="@+id/linearLayout" android:id="@+id/editPass" android:layout_width="match_parent" android:layout_height="wrap_content"/> <LinearLayout android:layout_marginStart="15dp" android:id="@+id/linearLayout" android:layout_above="@+id/buttonLogin" android:layout_alignEnd="@+id/buttonLogin" android:layout_alignStart="@+id/buttonLogin" android:layout_width="match_parent" android:layout_marginBottom="50dp" android:layout_height="wrap_content"> <CheckBox style="@style/Widget.AppCompat.CompoundButton.RadioButton" android:id="@+id/radioButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Remember Me" android:paddingStart="15dp" android:textColor="@color/white"/> <TextView android:visibility="invisible" android:id="@+id/textView" android:textColor="@color/white" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="end" android:text="Forgot Password"/> </LinearLayout> <android.support.v7.widget.AppCompatButton android:id="@+id/buttonLogin" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginEnd="30dp" android:layout_marginStart="30dp" android:background="@drawable/button_round_corner" app:backgroundTint="@color/colorOrangeUsSite" android:text="@string/login" android:textColor="@color/white"/> <FrameLayout android:background="@color/black" android:alpha="0.8" android:visibility="gone" android:id="@+id/layoutProgressBar" android:layout_width="match_parent" android:layout_height="wrap_content"> <ProgressBar android:theme="@style/ProgressBar" android:layout_gravity="center" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </FrameLayout> </RelativeLayout> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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