相关疑难解决方法(0)

如何在NestedScrollView中使用RecyclerView?

RecyclerView里面怎么用NestedScrollViewRecyclerView设置适配器后内容不可见.

UPDATE布局代码已更新.

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

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

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="@dimen/keyline_1">

    </RelativeLayout>

    <View
        android:id="@+id/separator"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#e5e5e5" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/conversation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview

189
推荐指数
13
解决办法
17万
查看次数

用于RecyclerView的GridLayoutManager上的方形布局

我尝试使用方形图像制作网格布局.我认为必须有可能GridLayoutManager通过操纵onMeasure来操纵

super.onMeasure(recycler, state, widthSpec, widthSpec); 
Run Code Online (Sandbox Code Playgroud)

代替

super.onMeasure(recycler, state, widthSpec, heightSpec);
Run Code Online (Sandbox Code Playgroud)

但不幸的是,这没有用.

有任何想法吗?

android gridlayoutmanager android-recyclerview

60
推荐指数
5
解决办法
3万
查看次数

更改RecyclerView gridlayout中的列数

我正在尝试根据显示大小更改回收器视图(网格布局)中显示的列数.但是我无法找到实现它的正确方法.目前我正在使用treeViewObserver根据屏幕大小的变化(在定向期间)更改列数.因此,如果应用程序以纵向模式打开,列数(在手机上)它决定为一个,看起来不错,但当应用程序直接以横向模式打开时,此方法不起作用,其中网格中有单个拉出的卡片显示在屏幕上.

这里recList是RecyclerView&glm是RecyclerView中使用的GridLayoutManager

    viewWidth = recList.getMeasuredWidth();

    cardViewWidthZZ = recList.getChildAt(0).getMeasuredWidth();

    if (oldWidth == 0) {
        oldWidth = cardViewWidthZZ;
    }

    if (oldWidth <= 0)
        return;

    int newSpanCount = (int) Math.floor(viewWidth / (oldWidth / 1.3f));
    if (newSpanCount <= 0)
        newSpanCount = 1;
    glm.setSpanCount(newSpanCount);
    glm.requestLayout();
Run Code Online (Sandbox Code Playgroud)

最好的祝福

android gridlayoutmanager

16
推荐指数
2
解决办法
2万
查看次数

RecyclerView getChildCount()和getItemCount()返回相同的值

RecyclerView有一个InfiniteScrollListener并且在该侦听器中,在OnScrolled()方法I中计算可见项和总项数以检查是否应该加载新项.当totalItemCount和visibleItemCount相同时,它会导致无限循环加载.听众与我RecyclerView没有CoordinatorLayoutNestedScrollView作为父母的其他人完美无瑕地工作.我想保留这种结构,因为客户不会接受更改.

我在活动中有一个像这样的布局的片段

CoordinatorLayout{
 NestedScrollView{
    RecyclerView{
    }
 }
}
Run Code Online (Sandbox Code Playgroud)

sdk版本

compileSdkVersion 24
buildToolsVersion "23.0.3"
...
minSdkVersion 21
targetSdkVersion 24
Run Code Online (Sandbox Code Playgroud)

fragment_profile.xml作为父布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay"
        app:layout_behavior="com.paxotic.paxira.util.behavior.AppBarFlingBehavior">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="@dimen/app_bar_height_small"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#000000"
                app:layout_collapseMode="parallax">

                <ImageView
                    android:id="@+id/img_background"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:alpha="0.5"
                    android:scaleType="centerCrop"
                    tools:src="@drawable/bg_greeting_activity" />

            </RelativeLayout>

        </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

    <include
        layout="@layout/activity_profile_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.FloatingActionButton
       ... />

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

fragment_profile.xml作为子布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto" …
Run Code Online (Sandbox Code Playgroud)

java android infinite-scroll

16
推荐指数
1
解决办法
1622
查看次数

NestedScroll与NestedScrollView,RecyclerView(水平),在CoordinatorLayout内

我有一个使用CollapsingToolbarLayout的UI设计,如下所示.

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/detail_backdrop_height"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.design.widget.CollapsingToolbarLayout

        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleMarginEnd="64dp"
        app:expandedTitleMarginStart="48dp"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:id="@+id/backdrop"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    </android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true"
    android:theme="@style/ThemeOverlay.AppCompat.Light"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

        <!-- Hiding unrelated code -->

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/card_margin"
            android:padding="16dp">


                <android.support.v7.widget.RecyclerView
                    android:id="@+id/recycler_movie_suggestion"
                    android:layout_width="match_parent"
                    android:layout_height="170dp"
                    android:fillViewport="true"
                    android:nestedScrollingEnabled="false"
                    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

            </LinearLayout>

        </android.support.v7.widget.CardView>

    </LinearLayout>

</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)

我的问题是,只有当我触摸并滚动RecyclerView外面的区域时滚动才能正常.如果我尝试在RecyclerView内部垂直滚动,则滚动"陷阱"并且只有NestedScrollView滚动,CollaspingToolbarLayout不会重叠.

android android-recyclerview coordinator-layout nestedscrollview

13
推荐指数
1
解决办法
1万
查看次数

当setNestedScrollingEnabled为false时,Recyclerview onscrolllistener无法正常工作

我想实现分页recyclerView,为此我添加addOnScrollListenerrecyclerView但是我在RecyclerView.OnScrollListener设置时没有工作的麻烦rvGridExplore.setNestedScrollingEnabled(false);

但当我删除rvGridExplore.setNestedScrollingEnabled(false);它工作正常,我不知道如何处理这个.

这是代码:

rvGridExplore = (RecyclerView) view.findViewById(R.id.rvGridExplore);
        final GridLayoutManager glm = new GridLayoutManager(context,2);
       // rvGridExplore.setNestedScrollingEnabled(false);
        rvGridExplore.setLayoutManager(glm);

       // final int visibleItemCount,totalCount,pastVisibleItems;
        rvGridExplore.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                Log.v("scrollll","state changed");
            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                if (dy > 0) {
                    int totalCount = glm.getItemCount();
                    int visibleItemCount = glm.getChildCount();
                    int pastVisibleItems = glm.findFirstVisibleItemPosition();
                    if (loading) { …
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview android-nestedscrollview

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

如何使用齐射将数据(json)加载到回收器视图中

我在我的应用程序中实现了recyclerview,现在我需要从服务器获取数据,我才知道volley是获取数据的最佳方式.我在网上搜索但我无法找到相同的教程.

这是我在我的代码中初始化recyclerview的方法.(具有硬编码数据集)

 mRecyclerView = (RecyclerView) findViewById(R.id.recyclerview);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    mRecyclerView.setLayoutManager(linearLayoutManager);

    mAdapter = new CardAdapter();
    mRecyclerView.setAdapter(mAdapter);  
Run Code Online (Sandbox Code Playgroud)

这是适配器代码.

public class CardAdapter extends RecyclerView.Adapter<CardAdapter.ViewHolder> {

ArrayList<BusRouteNameDetails> mItems;
public int TAG=0;

public CardAdapter() {
    super();
    mItems = new ArrayList<>();
    BusRouteNameDetails routename = new BusRouteNameDetails();
    routename.setName("xyz");
    routename.setNumber("X4");

    mItems.add(routename);

    routename = new BusRouteNameDetails();
    routename.setName("xyz");
    routename.setNumber("X4");

    mItems.add(routename);

    routename = new BusRouteNameDetails();
    routename.setName("xyz");
    routename.setNumber("X4");

    mItems.add(routename);

    routename = new BusRouteNameDetails();
    routename.setName("xyz");
    routename.setNumber("X4");

    mItems.add(routename);


    routename = new BusRouteNameDetails();
    routename.setName("xyz");
    routename.setNumber("X4");

    mItems.add(routename);
}

@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, …
Run Code Online (Sandbox Code Playgroud)

json android-volley android-recyclerview

5
推荐指数
1
解决办法
2万
查看次数

NestedScrollView 内的 RecyclerView 导致 RecyclerView 膨胀所有元素

我在将 RecyclerView 放置在 NestedScrollView 中时遇到问题,这会导致呈现 RecyclerView 适配器的所有元素。

这是一个相当大的问题,因为 RecyclerView 显示的列表可能包含数百个元素。

目前这会导致相当多的延迟(显然),因为它必须一次渲染所有视图,并且不能像 RecyclerView 通常那样重用任何已经膨胀的视图。

这是我当前的 XML(删除了一些膨胀以最小化它):

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:overScrollMode="never">

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

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="90dp">

            <!-- Some content -->

        </RelativeLayout>

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

            <!-- Some more content -->

        </LinearLayout>

        <!-- Product list -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:id="@+id/title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="12dp"/>

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recyclerview"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:overScrollMode="never"/>

        </LinearLayout>

    </LinearLayout>

</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)

这是我的 onCreateView() 来自 Fragment,它正在膨胀包含 NestedScrollView 和 RecyclerView 的视图:

@Override
public View onCreateView(LayoutInflater inflater, …
Run Code Online (Sandbox Code Playgroud)

xml android scrollview android-recyclerview nestedscrollview

5
推荐指数
1
解决办法
3295
查看次数

RecylerView以固定的第一行作为标题

我想创建一个带有固定第一行的循环器视图,它应该作为标题.另外,如何防止它与其他行元素一起滚动?

android android-recyclerview

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