Recyclerview下的按钮不可见

时间:2016-10-12 16:50:28

标签: android android-recyclerview

我正在使用RecyclerView和底部按钮编写应用程序。 RecyclerView正在填写我从服务器获取的图像。顶栏是固定的

http://joxi.ru/KAxee4XTEMpPr8

RecyclerView代码

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    />

RecyclerView由ImageViews

填写
 <ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
android:scaleType="centerCrop"
android:layout_marginBottom="1dp"
android:layout_marginEnd="1dp"
android:layout_marginStart="1dp"
android:layout_marginTop="1dp" />

不可见的按钮代码

 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="3">

    <ru.noorsoft.rubkoff.HeButton
        android:id="@+id/button1"
        style="@style/leftButStyle"
        android:layout_width="wrap_content"
        android:layout_height="55dp"
        android:layout_weight="1"
        android:gravity="center"
        android:textAllCaps="false"
        android:textColor="@color/colorBlue"
        android:textSize="20sp" />

    <ru.noorsoft.rubkoff.HeButton
        android:id="@+id/button2"
        android:background="@android:color/transparent"
        android:layout_width="wrap_content"
        android:layout_height="55dp"
        android:layout_weight="1"
        android:textColor="@color/colorBlue"
        android:textAllCaps="false"
        android:textSize="20sp" />

    <ru.noorsoft.rubkoff.HeButton
        android:id="@+id/button3"
        style="@style/rightButStyle"
        android:layout_width="wrap_content"
        android:layout_height="55dp"
        android:layout_weight="1"
        android:textColor="@color/colorBlue"
        android:textAllCaps="false"
        android:textSize="20sp" />

</LinearLayout>

2 个答案:

答案 0 :(得分:1)

我用另一种方式解决了这个问题。我在RecyclerView中提供了一个PaddingBottom,用于计算按钮的大小。例如,如果按钮的总大小为40 dp,则给PaddingBottom 50dp。这就是为什么Button不与RecyclerView重叠

<?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:background="@color/background"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".ui.fragment.tutorPanel.tutorProfile.quiz.TestFragment">

    <androidx.cardview.widget.CardView
        android:id="@+id/timer_cardView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_marginStart="10dp"
        android:layout_marginEnd="10dp"
        app:cardCornerRadius="12dp"
        app:cardElevation="0dp">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="@dimen/_5sdp"
            android:orientation="vertical">

            <TextView
                android:id="@+id/test_title_textView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Paper 03"
                android:textSize="13dp"
                android:textColor="@color/colorAccent"
                android:fontFamily="@font/inter_semi_bold"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.0" />

            <TextView
                android:id="@+id/time_remaining_textView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:drawableStart="@drawable/ic_clock"
                android:drawablePadding="5dp"
                android:text="Time Remaining"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/test_title_textView" />

            <TextView
                android:id="@+id/time_remaining_text_view"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="05:00"
                android:textSize="20dp"
                android:textColor="@color/colorAccent"
                android:fontFamily="@font/inter_semi_bold"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/time_remaining_textView"/>

        </androidx.constraintlayout.widget.ConstraintLayout>

    </androidx.cardview.widget.CardView>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/question_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:paddingBottom="55dp"
        android:layout_below="@+id/timer_cardView"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
        tools:itemCount="5"
        tools:listitem="@layout/item_question" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginStart="10dp"
        android:layout_marginEnd="10dp"
        android:layout_marginBottom="10dp"
        android:paddingTop="7dp"
        android:paddingBottom="7dp"
        android:gravity="center"
        android:background="@drawable/login_sign_up_button_state"
        android:text="Submit Answer"
        android:textColor="@color/white"
        android:textSize="15dp"
        android:fontFamily="@font/inter_semi_bold"/>

</RelativeLayout>

TextView的宽度为(15 + 10 + 7 + 7)〜40dp。所以我在RecyclerView中给了PaddingBottom 50dp

答案 1 :(得分:0)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools">

    <RelativeLayout
        android:id="@+id/header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <!-- here goes the header -->
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="header"/>
    </RelativeLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:listitem="@android:layout/simple_gallery_item"
        android:layout_below="@id/header"
        android:clipToPadding="false"

        android:paddingBottom="55dp"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="55dp"
        android:orientation="horizontal"
        android:layout_alignParentBottom="true"
        android:weightSum="3">

        <ru.noorsoft.rubkoff.HeButton
            android:id="@+id/button1"
            style="@style/leftButStyle"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:textAllCaps="false"
            android:textColor="@color/colorBlue"
            android:textSize="20sp" />

        <ru.noorsoft.rubkoff.HeButton
            android:id="@+id/button2"
            android:background="@android:color/transparent"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:textColor="@color/colorBlue"
            android:textAllCaps="false"
            android:textSize="20sp" />

        <ru.noorsoft.rubkoff.HeButton
            android:id="@+id/button3"
            style="@style/rightButStyle"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:textColor="@color/colorBlue"
            android:textAllCaps="false"
            android:textSize="20sp" />
    </LinearLayout>
</RelativeLayout>