android - 如何在Android Studio中的 Activity 底部制作Android xml Linearlayout?

标签 android xml android-studio android-linearlayout

如何在页面底部的Android Studio中制作LinearLayout。以下代码的结果

我希望突出显示的变暗布局位于页面底部。 I want the highlighted darken layout to be at the bottom of the page.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout    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"
    android:orientation="vertical"
    android:background="#ffffff">

<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"/>

    <!--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: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>

在上面的代码中,我尝试了下面的代码,但没有成功。

android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:gravity="bottom"

最佳答案

可以在外面使用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>

关于android - 如何在Android Studio中的 Activity 底部制作Android xml Linearlayout?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61565965/

相关文章:

java - android fragment 的最佳实践?

javascript - 自定义搜索字段属性以自定义文本 "No Data"

Android Studio Gradle 错误 BuildActionExecuter.withCancellationToken

macos - 将 IntelliJ 与 X11 转发结合使用

android - 在没有支持库的情况下在 Android 中设置 Renderscript

android - 在 Android < 7.1.1 上制作应用程序信任 Let's Encrypt ISRG Root X1

python - 文本提取中的断词, Lxml Xpath

python - 如何将我的 python 脚本分成两个并让它们像一个一样运行?

php - Volley POST 字符串请求意外错误 500

android - 如何对未发布的应用程序进行 Beta 测试?