【问题标题】:Buttons Are No Longer Clickable After I add RecyclerView to Layout将 RecyclerView 添加到布局后,按钮不再可点击
【发布时间】:2020-03-21 18:18:15
【问题描述】:

在我将 RecyclerView 添加到我的布局之前,我能够单击“TextView”(android:id="@+id/how_is_your_day_question"),它已被编程为能够单击。将 RecylerView 添加到布局后,我无法再单击此 TextView。我玩过布局,似乎无法弄清楚。当我单击 TextView 时,Logcat 显示“I/Surface: opservice is null false”。删除 RecyclerView 后,我可以再次单击 TextView 项,它的行为符合预期。我将不胜感激任何帮助。提前谢谢!

更新:在将 MARGIN_TOP 添加到回收站视图后,我能够解决问题 - 非常愚蠢的错误。哈哈

<androidx.drawerlayout.widget.DrawerLayout
    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:id="@+id/drawer_layout"
    android:fitsSystemWindows="true"
    tools:context=".Personal_Wall"
    tools:openDrawer="end">






    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">



            <androidx.appcompat.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="#ffff"
            android:id="@+id/toolbar"
            android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            elevation="4dp">



            <ImageView
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:id="@+id/hapana_button"
                android:text="hapana_button"
                android:layout_gravity="right"
                android:paddingRight="10dp"
                android:src="@drawable/ic_hapana_button2"/>


        </androidx.appcompat.widget.Toolbar>


        <androidx.core.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:overScrollMode="never"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            android:fillViewport="true">




        <RelativeLayout
                android:id="@+id/fragment-containter2"
                android:layout_width="match_parent"
                android:layout_height="match_parent">




                <TextView
                android:id="@+id/assists_number"
                android:layout_marginTop="10dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="46dp"
                android:textSize="12dp"
                android:text="15 Assists *" />

            <TextView
                android:id="@+id/followers_number"
                android:layout_marginTop="10dp"
                android:layout_marginLeft="280dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="12dp"
                android:text="1000 Followers *" />




            <de.hdodenhof.circleimageview.CircleImageView
                android:id="@+id/profile_place_holder"
                android:layout_width="160dp"
                android:layout_height="160dp"
                android:layout_marginTop="120dp"
                android:layout_gravity="center_horizontal"
                android:src="@drawable/profile_place_holder"
                app:civ_border_color="#fff"
                android:elevation="4dp"
                app:civ_border_width="5dp" />

            <androidx.cardview.widget.CardView
                xmlns:card_view="http://schemas.android.com/apk/res-auto"
                android:layout_width="wrap_content"
                android:layout_height="200dp"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="40dp"
                card_view:cardBackgroundColor="#fff"
                card_view:cardCornerRadius="8dp">

            <ImageView
                android:id="@+id/temporary_banner_personal_wall"
                android:layout_width="380dp"
                android:layout_height="200dp"
                android:scaleType="centerCrop"
                android:adjustViewBounds="true"
                android:layout_gravity="center_horizontal"
                app:srcCompat="@drawable/ic_hapana_banner_2"/>
            </androidx.cardview.widget.CardView>




            <TextView
                android:id="@+id/edit_text_first_name"
                android:layout_width="193dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="125dp"
                android:layout_marginRight="50dp"
                android:layout_marginTop="290dp"
                android:layout_weight="0.5"
                android:background="@android:color/transparent"
                android:ems="10"
                android:fontFamily="@font/roboto_medium"
                android:inputType="textPersonName"
                android:text="First"
                android:textColor="#000"
                android:textSize="20dp" />

            <TextView
                android:id="@+id/edit_text_last_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="220dp"
                android:layout_marginTop="290dp"
                android:background="@android:color/transparent"
                android:ems="10"
                android:fontFamily="@font/roboto_medium"
                android:inputType="textPersonName"
                android:text="Last"
                android:textSize="20dp"
                android:layout_weight="0.5"
                android:textColor="#000"/>

            <RatingBar
                android:id="@+id/ratingBar_profile"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="350dp"
                android:layout_gravity="center_horizontal"
                android:scaleX="0.7"
                android:scaleY="0.7"
                android:rating="5"
                android:isIndicator="true"/>

            <View
                android:layout_width="match_parent"
                android:layout_height="10dp"
                android:layout_marginTop="540dp"
                android:background="@android:color/darker_gray" />



            <TextView
                android:id="@+id/current_location"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="330dp"
                android:layout_marginLeft="60dp"
                android:textColor="#000"
                android:drawableLeft="@drawable/ic_profile_location_on_black_24dp"
                android:drawablePadding="10dp"
                android:text="Current Location:   City, State" />

            <ImageButton
                android:id="@+id/postsomething"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="460dp"
                android:background="@color/fui_transparent"
                app:srcCompat="@drawable/ic_posting_line"/>




            <TextView
                android:id="@+id/how_is_your_day_question"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="430dp"
                android:layout_marginLeft="25dp"
                android:textSize="18dp"
                android:textColor="#000"
                android:drawablePadding="10dp"
                android:text="How is your day?" />


            <TextView
                android:id="@+id/photo_with_icon_camera"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="480dp"
                android:layout_marginLeft="18dp"
                android:textColor="#000"
                android:drawablePadding="10dp"
                android:drawableLeft="@drawable/ic_profile_camera_grey"
                android:textSize="12dp"
                android:text= "Camera" />

            <TextView
                android:id="@+id/photo_with_icon_video_green"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="480dp"
                android:layout_marginLeft="97dp"
                android:textColor="#000"
                android:drawablePadding="10dp"
                android:drawableLeft="@drawable/ic_profile_video_grey"
                android:textSize="12dp"
                android:text= "Video" />




            <TextView
                android:id="@+id/photo_with_icon_gallery"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="480dp"
                android:layout_marginLeft="173dp"
                android:textColor="#000"
                android:drawablePadding="10dp"
                android:drawableLeft="@drawable/ic_profile_photo_grey"
                android:textSize="12dp"
                android:text= "Photos" />



            <ImageButton
                android:id="@+id/edit_icon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="280dp"
                android:layout_marginTop="245dp"
                android:background="@color/fui_transparent"
                app:srcCompat="@drawable/ic_edit_icon_2" />






            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recyclerView_profile_page"
                android:layout_width="match_parent"
                android:layout_height="match_patent"
                android:paddingTop="560dp"
                android:nestedScrollingEnabled="true"
                android:transcriptMode="alwaysScroll"
                android:fillViewport="true"
                app:layout_behavior="@string/appbar_scrolling_view_behavior">

            </androidx.recyclerview.widget.RecyclerView>




        </RelativeLayout>


        </androidx.core.widget.NestedScrollView>


    </LinearLayout>



    <com.google.android.material.navigation.NavigationView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:id="@+id/nav_view"
        app:headerLayout="@layout/nav_header"
        app:menu="@menu/drawer_menu"/>



</androidx.drawerlayout.widget.DrawerLayout>

【问题讨论】:

    标签: android android-studio android-recyclerview android-framelayout


    【解决方案1】:

    因为您的 recyclerview 的高度与父级匹配,而与 recycler 视图处于同一层次结构中的所有其他视图都将其高度设置为包装内容。这意味着回收器视图正在绘制上面声明的所有同级。

    我建议你在 RecyclerView 中更改 android:layout_height="wrap_content" 看看是否有什么不同。

    【讨论】:

    • 感谢您的帮助。不幸的是,当我运行应用程序时,该解决方案导致我的 RecyclerView 消失,并且我的 TextView 仍然不可点击。
    • 等一下,我先回老家把它贴到我的安卓工作室里让它工作。
    【解决方案2】:

    该问题已在较早的答案中得到解决。 RecyclerView 与其他项目重叠,因此它们不可点击。

    我建议去掉 FrameLayout 并将其替换为 ConstraintLayoutRelativeLayout 以便您可以定位每个项目而不会相互重叠。

    如果在RecyclerView 首先加载一个空列表之后加载列表,则wrap_content 有时会不起作用。

    更新

    将其更改为RelativeLayout 容器后,看起来它仍然覆盖了您布局中的所有项目。我建议在您的RecyclerView 中设置以下属性,如果现在可以解决您的点击问题,请告诉我。

    android:layout_below="@+id/how_is_your_day_question"
    

    【讨论】:

    • 感谢您的解决方案。我将 FrameLayout 更改为 RelativeLayout,不幸的是,它导致 TextView 仍然不可点击。
    • 您能分享一下您的最新布局吗?
    • 看起来RecyclerView 仍然与所有项目重叠。您是否有设计的屏幕截图,以便我们准确了解您想要什么?
    • 另外,你能看看我更新的答案吗?谢谢!
    • 嗨,我很抱歉。我有带有 match_parent 的 RecyclerView,但忘记在 stackoverflow 上更新它。我用 match_parent 尝试过,我的 RecyclerView 停止出现。我已经更新了stackoverflow中的代码。我不得不添加 NestledScrollView,因为我的 RecyclerVew 遇到了奇怪的滚动行为。它没有随着我页面的其余部分滚动,所以我不得不添加 NestledScrollview。但谢谢你的链接。我会看的。
    猜你喜欢
    • 1970-01-01
    • 2018-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多