【问题标题】:Android Horizontal RecyclerView wrap_contentAndroid Horizo​​ntal RecyclerView wrap_content
【发布时间】:2016-02-21 09:46:57
【问题描述】:

你好我正在尝试使用Recyclerview,

下面的代码结果只是一个空白屏幕,你能告诉我哪里出错了

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:gravity="top|center_vertical">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/ImageSelectorRecycler"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="horizontal" />

    <ImageView
        android:id="@+id/ImageViewSelectPhoto"
        android:layout_width="80dp"
        android:layout_height="76dp"
        android:src="@drawable/ic_add_a_photo_black_361px"
        android:background="@drawable/back"
        android:layout_marginRight="20dp"
        android:layout_marginBottom="20dp" />

</LinearLayout>

【问题讨论】:

    标签: android android-recyclerview android-wrap-content


    【解决方案1】:
    1. 既然你已经提供了

          android:layout_width="match_parent"
          android:layout_height="match_parent"
      

      对于您的 RecyclerView,它会占用您设备或父视图的全部宽度和高度。并且 ImageView 在设备屏幕之外。

    2. 现在您刚刚在 XML 中声明了 RecyclerView。您需要一个 RecyclerView 行布局,它应该定义 RecyclerView 项目的布局。

    要在 RecyclerView 中显示某些内容,您可以在 Row Layout 布局本身中设置静态数据,或者需要为动态/静态数据创建 RecyclerView 适配器和模型。

    【讨论】:

      【解决方案2】:

      你需要为你的水平滚动视图和一个单独的适配器创建一个列表项布局。

      尝试添加android:viewfillport="true"

      我也问过类似的问题,请看一下,你一定会得到一个简单的方法来实现这个。

      Horizontal Listview Not Working from github

      【讨论】:

        【解决方案3】:

        我觉得应该和这个差不多

        <?xml version="1.0" encoding="utf-8"?>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:gravity="top|center_vertical">
        
        <android.support.v7.widget.RecyclerView
            android:id="@+id/ImageSelectorRecycler"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="match_parent"/>
        
        <ImageView
            android:id="@+id/ImageViewSelectPhoto"
            android:layout_width="80dp"
            android:layout_height="76dp"
            android:layout_marginRight="20dp"
            android:layout_marginBottom="20dp"
            android:src="@android:drawable/ic_dialog_alert"
            android:background="@android:color/holo_green_dark" />
        
        </LinearLayout>
        

        【讨论】:

        • 不工作...我可以看到 imageview 但 recyclerview 不见了
        • 对不起,我搞错了
        猜你喜欢
        • 2019-03-30
        • 2016-12-09
        • 1970-01-01
        • 1970-01-01
        • 2019-06-29
        • 2016-03-19
        • 2015-06-13
        • 2021-10-22
        • 1970-01-01
        相关资源
        最近更新 更多