Framelayout在constraintlayout中没有出现在RecyclerView的顶部

问题描述 投票:0回答:1

我是这个Android编程的新手。

我正在尝试在回收器视图(这是ConstraintLayout的一部分,我需要将FAB定位在屏幕的右下角)上有一个framelayout和textview,但它似乎没有出现。

一些帮助和建议为什么会发生这种情况以及应该做些什么。

<?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"
    android:background="#E0E0E0"
    tools:context="com.testapp.testapp.HomeActivity">
    <FrameLayout
        android:id="@+id/org_store_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:paddingBottom="12dp"
        android:paddingLeft="12dp"
        android:paddingRight="12dp">

            <TextView
                android:id="@+id/order_ID"
                style="@style/AppTheme.Subheader"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="0dp"
                android:layout_marginStart="8dp"
                android:layout_marginTop="-2dp"
                android:ellipsize="end"
                android:maxLines="1"
                android:visibility="visible"
                tools:text="Order #: 0001123" />
    </FrameLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_orders"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        tools:listitem="@layout/item_orders"

        />

    <View
        android:layout_width="match_parent"
        android:layout_height="4dp"
        android:layout_below="@+id/recycler_orders"
        android:background="@drawable/bg_shadow" />

    <!-- Empty list (pizza guy) view ... havent tested empty view-->
    <android.support.constraint.ConstraintLayout
        android:id="@+id/view_empty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:gravity="center"
        android:orientation="vertical"
        android:visibility="gone"
        tools:visibility="gone">

        <ImageView
            style="@style/AppTheme.PizzaGuy"
            android:contentDescription="@string/message_no_results"
            android:src="@drawable/pizza_monster" />

        <TextView
            style="@style/AppTheme.Body1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="@string/message_no_results"
            android:textColor="@color/grey_300" />
    </android.support.constraint.ConstraintLayout>

    <ProgressBar
        android:id="@+id/progress_loading"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/recycler_orders"
        android:layout_alignTop="@+id/recycler_orders"
        android:layout_centerHorizontal="true"
        android:visibility="gone" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_addnew"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        app:backgroundTint="@color/colorAccent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:srcCompat="@drawable/ic_add_white_24px" />

</android.support.constraint.ConstraintLayout>
android android-recyclerview android-framelayout
1个回答
0
投票

ConstraintLayout的好处在于它非常强大,您不再需要使用嵌套布局。因此,在您的情况下,不需要嵌套的FrameLayout和嵌套的ConstraintLayout。

例如,您可以直接在order_ID TextView上指定背景和填充,并且可以摆脱FrameLayout。此外,view_empty中的所有内容都可以直接作为主ContraintLayout的子项。布局中缺少的是约束! ConstraintLayout需要约束才能知道绘制子项的位置,但是您没有提供任何约束!这意味着,由于布局不知道在哪里绘制东西,所以一切都将在布局本身的左上角。

最后一件事:ConstraintLayout与ltr和rtl语言完美配合。因此,最好使用marginStart和marginEnd,而不是marginLeft和marginRight。

© www.soinside.com 2019 - 2024. All rights reserved.