如何将textView放在回收器视图的顶部?

时间:2018-11-15 19:34:30

标签: android

我有一个recyclerView(Shimmer RecyclerView)和一个晶圆厂。我需要显示我的晶圆厂的描述,但是当我在xml文件中放置textView时,textView显示在recyclerView的后面,而我需要在recyclerView的顶部。知道如何获得不良结果吗?

我的代码:

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

        <android.support.design.widget.FloatingActionButton
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_gravity="bottom|left"
            android:layout_marginLeft="10dp"
            android:layout_marginBottom="10dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|left"
            android:layout_marginLeft="80dp"
            android:layout_marginBottom="21dp"
            android:background="@drawable/dark_gray_rounded"
            android:gravity="center"
            android:padding="10dp"
            android:text="someText"
            android:textColor="@color/white" />

        <com.cooltechworks.views.shimmer.ShimmerRecyclerView xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipToPadding="false"
            android:paddingTop="15dp"
            app:shimmer_demo_angle="35"
            app:shimmer_demo_child_count="10"
            app:shimmer_demo_layout_manager_type="linear_vertical"
            app:shimmer_demo_reverse_animation="true" />
    </android.support.design.widget.CoordinatorLayout>

3 个答案:

答案 0 :(得分:3)

尝试一下:

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

<android.support.design.widget.FloatingActionButton
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:layout_gravity="bottom|left"
    android:layout_marginLeft="10dp"
    android:layout_marginBottom="10dp" />

<com.cooltechworks.views.shimmer.ShimmerRecyclerView xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false"
    android:paddingTop="15dp"
    app:shimmer_demo_angle="35"
    app:shimmer_demo_child_count="10"
    app:shimmer_demo_layout_manager_type="linear_vertical"
    app:shimmer_demo_reverse_animation="true"/>

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|left"
    android:layout_marginLeft="80dp"
    android:layout_marginBottom="21dp"
    android:background="@drawable/dark_gray_rounded"
    android:gravity="center"
    android:padding="10dp"
    android:text="someText"
    android:textColor="@color/white" />

我已经尝试过了。它的作用与您所希望的相同。希望这项工作对您有用。

答案 1 :(得分:1)

CoordinatorLayoutFrameLayout扩展而来,因此子View堆叠在前一个FloatingActionButton之上(View作为例外,因为此{{1 }}专门由CoordinatorLayout管理。

因此,您需要交换TextViewRecyclerView以获得所需的效果(至少与“正常” RecyclerView一起使用)

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

    <android.support.design.widget.FloatingActionButton
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_gravity="bottom|left"
        android:layout_marginLeft="10dp"
        android:layout_marginBottom="10dp" />

    <com.cooltechworks.views.shimmer.ShimmerRecyclerView xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:paddingTop="15dp"
        app:shimmer_demo_angle="35"
        app:shimmer_demo_child_count="10"
        app:shimmer_demo_layout_manager_type="linear_vertical"
        app:shimmer_demo_reverse_animation="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|left"
        android:layout_marginLeft="80dp"
        android:layout_marginBottom="21dp"
        android:background="@drawable/dark_gray_rounded"
        android:gravity="center"
        android:padding="10dp"
        android:text="someText"
        android:textColor="@color/white" />
</android.support.design.widget.CoordinatorLayout>

答案 2 :(得分:0)

在单独的布局中组织fab和textView,并将其包含在您的coordinatorLayout中