相关疑难解决方法(0)

如何使用RecyclerView显示空视图?

我习惯在布局文件中放置一个特殊视图,ListActivity没有数据时显示文档中所述.此视图具有id "android:id/empty".

<TextView
    android:id="@android:id/empty"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/no_data" />
Run Code Online (Sandbox Code Playgroud)

我想知道如何用新的方式做到这一点RecyclerView

android listview no-data android-recyclerview

249
推荐指数
10
解决办法
15万
查看次数

如何使WRAP_CONTENT在RecyclerView上运行

我有一个DialogFragment包含RecyclerView(卡片列表).

其中RecyclerView一个或多个CardViews可以具有任何高度.

我想DialogFragment根据CardViews其中包含的内容给出正确的高度.

通常情况下,这将是简单的,我会成立wrap_contentRecyclerView这个样子.

<android.support.v7.widget.RecyclerView ...
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"   
    android:clickable="true"   
    android:scrollbars="vertical" >

</android.support.v7.widget.RecyclerView>
Run Code Online (Sandbox Code Playgroud)

因为我使用的RecyclerView这个不起作用,请看:

https://issuetracker.google.com/issues/37001674

嵌套的Recycler视图高度不会包装其内容

在这两个页面上,人们建议扩展LinearLayoutManager和覆盖onMeasure()

我首先使用了第一个链接中提供的LayoutManager:

public static class WrappingLayoutManager extends LinearLayoutManager {

        public WrappingLayoutManager(Context context) {
            super(context);
        }

        private int[] mMeasuredDimension = new int[2];

        @Override
        public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state,
                              int widthSpec, int heightSpec) {
            final int widthMode = View.MeasureSpec.getMode(widthSpec);
            final …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-fragments android-studio android-recyclerview

176
推荐指数
8
解决办法
12万
查看次数

嵌套的Recycler视图高度不会包装其内容

我有一个应用程序来管理书籍集(如播放列表).

我想显示一个带有垂直RecyclerView的集合列表,并在每行内部显示一个水平RecyclerView中的书籍列表.

当我将内部水平RecyclerView的layout_height设置为300dp时,它会正确显示,但是当我将其设置为wrap_content时,它不会显示任何内容. 我需要使用wrap_content,因为我希望能够以编程方式更改布局管理器以在垂直和水平显示之间切换.

在此输入图像描述

你知道我做错了什么吗?

我的片段布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/white">

    <com.twibit.ui.view.CustomSwipeToRefreshLayout
        android:id="@+id/swipe_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

            <android.support.v7.widget.RecyclerView
                android:id="@+id/shelf_collection_listview"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingTop="10dp"/>

        </LinearLayout>

    </com.twibit.ui.view.CustomSwipeToRefreshLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

集合元素布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="vertical">

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="#FFF">

        <!-- Simple Header -->

    </RelativeLayout>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="@string/empty_collection"
            android:id="@+id/empty_collection_tv"
            android:visibility="gone"
            android:gravity="center"/>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/collection_book_listview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/> <!-- android:layout_height="300dp" -->

    </FrameLayout>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

书目项目:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="180dp"
              android:layout_height="220dp"
              android:layout_gravity="center">

        <ImageView
            android:id="@+id/shelf_item_cover"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:maxWidth="150dp"
            android:maxHeight="200dp"
            android:src="@drawable/placeholder"
            android:contentDescription="@string/cover"
            android:adjustViewBounds="true"
            android:background="@android:drawable/dialog_holo_light_frame"/> …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-support-library android-studio android-recyclerview

172
推荐指数
10
解决办法
10万
查看次数