Android - RelativeLayout w / RecyclerView和Anchored Button

时间:2016-03-21 14:47:54

标签: android android-recyclerview relativelayout

首先,我感谢我在这个问题上可以得到的任何帮助,因为它让我在过去的两天里摸不着头脑。

我有一个RelativeLayout包装一个Button和一个RecyclerView,Button与父母的底部对齐,RecyclerView与父母的顶部对齐(以及Button上方)。因此,我试图始终将按钮固定在屏幕底部并在其上方放置RecyclerView(在RecyclerView中最多只有3个项目作为用户的最佳选项)。

当我这样做时,按钮总是按预期显示在页面底部。但是,按钮永远不会触发点击事件,这对我来说真是令人头疼。这是一个非常奇怪的部分,如果我用一个TextView替换RecyclerView(仅用于测试按钮),则会触发click事件。然后我可以重新使用RecyclerView并且不会再次触发click事件。我在应用程序中的多个其他位置工作的RelativeLayout中有一个锚定按钮的概念,但是这个(只有一个RecyclerView)给我带来了问题。

我的目标是SDK版本23,并使用23.X版本的所有构建工具和支持库。

就像FYI一样,这个片段的根元素和此时片段上唯一的其他视图是FrameLayout。如果我不需要在应用程序的这一部分完成后再对图片上的按钮(例如FloatingActionButton)进行分层,那么我将在那时使RelativeLayout成为片段的根布局。

<-- Options Container -->
<RelativeLayout android:id="@+id/container"
              android:gravity="top"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:scrollbarAlwaysDrawVerticalTrack="true" >

    <!-- More Options Button -->
    <Button android:id="@+id/more_options"
            android:padding="24dp"
            android:clickable="true"
            android:layout_gravity="center_horizontal"
            android:text="@string/more_options"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_alignParentBottom="true" />

    <!-- List of Optimal Options -->
    <FrameLayout android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:layout_alignParentTop="true"
                 android:layout_above="@+id/more_options" >
        <android.support.v7.widget.RecyclerView
                android:scrollbars="vertical"
                android:clipChildren="false"
                android:clipToPadding="false"
                android:paddingTop="8dp"
                android:paddingBottom="8dp"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:id="@+id/optimal_options_recycler" />
    </FrameLayout>
</RelativeLayout>

0 个答案:

没有答案