繁体   English   中英

如何在coordinatorLayout内的RelativeLayout底部对齐LinearLayout

[英]how to align LinearLayout at the bottom of RelativeLayout inside coordinatorLayout

我在CoordinatorLayout中有一个RelativeLayout和LinearLayout。 我想将LinearLayout对准RelativeLayout的底部。 但是下面的布局在这里不起作用。 我不知道如何实现这一点。

这是我的代码

<android.support.design.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <RelativeLayout
                android:id="@+id/top"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="150dp"
                    android:src="@drawable/artboard_signup"
                    android:scaleType="fitXY"
                    android:visibility=""
                    />

            </RelativeLayout>



            <LinearLayout
                android:id="@+id/bottom"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginTop="170dp">

                <LinearLayout
                    android:layout_weight="7"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:paddingTop="15dp"
                        android:paddingLeft="10dp"
                        android:paddingRight="10dp"
                        android:text="Top Bootable Antivirus For Your PC?"/>

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="8 hours ago"
                        android:paddingLeft="10dp"/>

                </LinearLayout>
        </LinearLayout>
    </android.support.design.widget.CoordinatorLayout>

我希望ID底部为LinearLayout的ID顶部为RelativeLayout的底部。

无论如何,我可以实现这一目标。

尝试在android:id="@+id/bottom"之后添加android:layout_gravity="bottom" android:id="@+id/bottom"

使用RelativeLayout而不是CoordinateLayout,然后在LearLayout中添加“ android:layout_alignParentBottom =“ true”“行。

<?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">
    <RelativeLayout
        android:id="@+id/top"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="150dp"
            app:srcCompat="@drawable/ic_call_black_24dp"
            android:scaleType="fitXY"
            android:visibility="visible"
            />

    </RelativeLayout>



    <LinearLayout
        android:id="@+id/bottom"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="170dp"
        android:layout_alignParentBottom="true">

        <LinearLayout
            android:layout_weight="7"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingTop="15dp"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                android:text="Top Bootable Antivirus For Your PC?"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="8 hours ago"
                android:paddingLeft="10dp"/>

        </LinearLayout>
    </LinearLayout>

也许这会工作。 试试吧。

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<RelativeLayout
    android:id="@+id/top"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:scaleType="fitXY"
        android:src="@drawable/artboard_signup"
        android:visibility="" />

    <LinearLayout
        android:id="@+id/bottom"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginTop="170dp"
        android:orientation="horizontal">

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="7"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="10dp"
                android:paddingTop="15dp"
                android:paddingRight="10dp"
                android:text="Top Bootable Antivirus For Your PC?" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="10dp"
                android:text="8 hours ago" />

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

解:

只需在<CoordinatorLayout>内添加<LinearLayout> <CoordinatorLayout> ,如下所示:

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

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

        <RelativeLayout
            android:id="@+id/top"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="150dp"
                android:src="@drawable/artboard_signup"
                android:scaleType="fitXY"
                android:visibility=""
                />

        </RelativeLayout>



        <LinearLayout
            android:id="@+id/bottom"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_marginTop="170dp">

            <LinearLayout
                android:layout_weight="7"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingTop="15dp"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp"
                    android:text="Top Bootable Antivirus For Your PC?"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="8 hours ago"
                    android:paddingLeft="10dp"/>

            </LinearLayout>
        </LinearLayout>
    </LinearLayout>
</android.support.design.widget.CoordinatorLayout>

希望它能工作。

暂无
暂无

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

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