如何使Android xml Linerlayout位于Android Studio活动的底部?

如何使Android xml Linerlayout位于Android Studio活动的底部?,android,xml,android-studio,android-linearlayout,Android,Xml,Android Studio,Android Linearlayout,如何在页面底部的Android Studio中进行线性布局。下面代码的结果 我希望突出显示的深色布局位于页面底部。 您可以在外部使用RelativeLayout。类似于此,然后在其后添加新的LinearLayout <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="h

如何在页面底部的Android Studio中进行线性布局。下面代码的结果

我希望突出显示的深色布局位于页面底部。


您可以在外部使用RelativeLayout。类似于此,然后在其后添加新的LinearLayout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:orientation="vertical"
    tools:context=".MainPage">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <Button
            android:id="@+id/taptoscan"
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:layout_gravity="center"
            android:layout_marginTop="40dp"
            android:layout_marginBottom="10dp"
            android:background="@drawable/barcode" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:fontFamily="@font/antic"
            android:text="Tap to Scan"
            android:textSize="18sp" />
    </LinearLayout>

    <!--here is the layout i want to put at the bottom of the page-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_alignParentBottom="true"
        android:layout_gravity="bottom"
        android:background="@color/colorPrimaryDark"
        android:gravity="bottom"
        android:orientation="horizontal">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    </LinearLayout>
</RelativeLayout>

使用框架布局作为基本布局,以最佳方式完成,它肯定会工作 只需在线性布局中使用layout_gravity=“bottom”,您需要在底部和底部使用该布局 就这样,

  <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:orientation="vertical"
    tools:context=".MainPage">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <Button
            android:id="@+id/taptoscan"
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:layout_gravity="center"
            android:layout_marginTop="40dp"
            android:layout_marginBottom="10dp"
            android:background="@drawable/barcode" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:fontFamily="@font/antic"
            android:text="Tap to Scan"
            android:textSize="18sp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_gravity="bottom"
        android:background="@color/colorPrimaryDark"
        android:orientation="horizontal">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    </LinearLayout>

</FrameLayout>

以下方法将帮助您实现零重叠的设计规范。基本上,有四个关键步骤:

  • 将根布局更改为RelativeLayout

  • 在RelativeLayout中,添加包含按钮和文本视图的LinearLayout

  • 在相同的RelativeLayout中,添加要固定到屏幕底部的LinearLayout

  • 确保使用
    android:layout_over=”“
    属性将第一个线性布局设置在第二个线性布局之上

  • 下面是代码:

    <?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=".MainPage">
    
    
      <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical"
          android:background="#ffffff"
          android:layout_above="@+id/bottomView">
    
    
          <Button
              android:id="@+id/taptoscan"
              android:layout_marginTop="40dp"
              android:layout_marginBottom="10dp"
              android:layout_width="120dp"
              android:layout_height="120dp"
              android:background="@drawable/barcode"
              android:layout_gravity="center"/>
    
          <TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Tap to Scan"
              android:fontFamily="@font/antic"
              android:layout_gravity="center"
              android:textSize="18sp"/>
    
      </LinearLayout>
    
      <!--here is the layout i want to put at the bottom of the page-->
      <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="40dp"
          android:id="@+id/bottomView"
          android:background="@color/colorPrimaryDark"
          android:orientation="horizontal"
          android:layout_alignParentBottom="true"
          android:layout_gravity="bottom"
          android:gravity="bottom">
    
          <RelativeLayout
              android:layout_width="wrap_content"
              android:layout_height="wrap_content">
          </RelativeLayout>
    
      </LinearLayout>
    
    </RelativeLayout>
    
    
    

    我希望这会有帮助。

    把外套当作relativelayout@Ticherhaz我也试过了它不起作用
      <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ffffff"
        android:orientation="vertical"
        tools:context=".MainPage">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
    
            <Button
                android:id="@+id/taptoscan"
                android:layout_width="120dp"
                android:layout_height="120dp"
                android:layout_gravity="center"
                android:layout_marginTop="40dp"
                android:layout_marginBottom="10dp"
                android:background="@drawable/barcode" />
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:fontFamily="@font/antic"
                android:text="Tap to Scan"
                android:textSize="18sp" />
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_gravity="bottom"
            android:background="@color/colorPrimaryDark"
            android:orientation="horizontal">
    
        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        </LinearLayout>
    
    </FrameLayout>
    
    <?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=".MainPage">
    
    
      <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical"
          android:background="#ffffff"
          android:layout_above="@+id/bottomView">
    
    
          <Button
              android:id="@+id/taptoscan"
              android:layout_marginTop="40dp"
              android:layout_marginBottom="10dp"
              android:layout_width="120dp"
              android:layout_height="120dp"
              android:background="@drawable/barcode"
              android:layout_gravity="center"/>
    
          <TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Tap to Scan"
              android:fontFamily="@font/antic"
              android:layout_gravity="center"
              android:textSize="18sp"/>
    
      </LinearLayout>
    
      <!--here is the layout i want to put at the bottom of the page-->
      <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="40dp"
          android:id="@+id/bottomView"
          android:background="@color/colorPrimaryDark"
          android:orientation="horizontal"
          android:layout_alignParentBottom="true"
          android:layout_gravity="bottom"
          android:gravity="bottom">
    
          <RelativeLayout
              android:layout_width="wrap_content"
              android:layout_height="wrap_content">
          </RelativeLayout>
    
      </LinearLayout>
    
    </RelativeLayout>