相关疑难解决方法(0)

如何使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万
查看次数

RecyclerView占用所有屏幕空间

所以我在布局文件中遇到了一些RecyclerView问题

这里是:

<android.support.v7.widget.RecyclerView
    android:id="@+id/chat_listview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingRight="@dimen/abc_action_bar_default_padding_material"
    android:paddingLeft="@dimen/abc_action_bar_default_padding_material"
    />


<LinearLayout
    android:layout_below="@id/chat_listview"
    android:layout_width="match_parent"
    android:layout_height="@dimen/bottom_bar_height"
    android:orientation="horizontal"
    >

    <EditText
        android:id="@+id/chat_input_edittext"
        android:layout_weight="7"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:inputType="textAutoCorrect"
        />

    <Button
        android:id="@+id/chat_send_button"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:background="@drawable/ic_action_send_now"
        />

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

RecyclerView是可见的和可滚动的但是LinearLayout和里面的视图是不可见的...我尝试了很多东西,但到目前为止还没有任何工作.

你们中的任何人都可以指出我正确的方向吗?

提前谢谢了!

java xml android android-layout android-recyclerview

3
推荐指数
1
解决办法
2757
查看次数