代码之家  ›  专栏  ›  技术社区  ›  Pritish

将ConstraintLayout内的FrameLayout与底部对齐

  •  24
  • Pritish  · 技术社区  · 7 年前

    我希望在屏幕底部的回收器视图上方有一个布局(像一个框架),这样即使该布局可见,我仍然可以在其后面滚动回收器视图。所以我想对齐屏幕底部的框架布局,并根据需要使其可见和不可见。这是我的密码。

     <?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\u parentBottom这样的属性实现同样的效果。但没有一个属性可供使用。我需要做什么才能使框架布局在回收器视图的底部和顶部同时可见? 谢谢:)

    1 回复  |  直到 4 年前
        1
  •  48
  •   Community CDub    4 年前

    我想用align\u 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>