2

你好我正在尝试使用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>
4

3 回答 3

1

您需要为您的 Horizo​​ntal-scrollview 和一个单独的适配器制作一个列表项布局。

尝试添加android:viewfillport="true"

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

水平列表视图不适用于 github

于 2016-02-21T10:32:31.707 回答
1
  1. 既然你提供了

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

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

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

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

于 2016-02-21T10:18:58.633 回答
0

我认为它应该与此类似

<?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>
于 2016-02-21T12:08:40.910 回答