将FrameLayout在ConstraintLayout中对齐到底部

25

我希望在屏幕底部以上的可滚动视图中添加一个布局(如框架),即使该布局可见,我也仍然可以在其后滚动可滚动视图。因此,我想将框架布局与屏幕底部对齐,并根据需要设置其可见性。以下是我的代码。

 <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="com.protossoft.root.aesencryption.MainActivity">



    <ListView
        android:layout_width="match_parent"
        android:id="@+id/listView"
        android:layout_height="match_parent">

    </ListView>

  <!--  <RelativeLayout
        android:layout_width="match_parent"

        android:layout_height="wrap_content">-->
    <FrameLayout
        android:layout_width="match_parent"

        android:layout_height="wrap_content"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="443dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:gravity="center"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/deviceNumberImage"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.2"
                android:src="@android:drawable/btn_default" />

            <TextView
                android:id="@+id/deviceNumber"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.8"
                android:text="990000862471854" />

        </LinearLayout>
    </FrameLayout>
   <!-- </RelativeLayout>-->

我对约束布局并不是很了解,但当我从编辑器中移动底部视图时,它使用类似于

tools:layout_editor_absoluteX="0dp"
    tools:layout_editor_absoluteY="443dp"

我希望使用类似于align_parentBottom的属性来实现相同的效果。但是没有任何可用的属性可以使用。我需要做什么才能使框架布局同时可见于recycler view的顶部和底部呢?谢谢 :)

1个回答

53

我希望通过一些像align_parentBottom这样的属性来实现相同的效果。

您应该使用app:layout_constraintBottom_toBottomOf="parent"属性。

以下是您需要设置的内容:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    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">

    <FrameLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">
        ...
    </FrameLayout>

</android.support.constraint.ConstraintLayout>

完美运作。正是我所需要的。非常感谢。 - Atin Agrawal

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接