相关疑难解决方法(0)

处理RecyclerView,NestedScrollView和CardView

我将在我的应用程序中实现此UI: UI

好吧,我之前尝试过的一些方法:

1.使用CollapsingToolbarLayout 我把我CardView的insid CollapsingToolbarLayout并把他们都在AppBarLAyout.

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="scroll|exitUntilCollapsed" >

            <CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                />
                  <!-- My Views Goes there -->
            </CardView

            <android.support.v7.widget.Toolbar
                android:id="@+id/flexible.example.toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@null"
                app:layout_collapseMode="pin"
                style="@style/ToolBarWithNavigationBack"
                />
        </android.support.design.widget.CollapsingToolbarLayout>

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

    <RecyclerView
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
    ></RecyclerView>

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

PS:我删除了不相关的代码,不提我

这种方式正常但是!!! 当CardView高度高于屏幕高度时,它的内容由AppBarLayout用户显示并且不向用户显示

2.使用NestedScrollView 我放入CardViewRecyclerView内部NestedScrollView.但问题是当用户到达时回收到RecyclerView,然后滚动回到顶部,fling会变得迟钝和错误并停止一些用户必须滚动越来越多的地方!

<android.support.v4.widget.NestedScrollView
    android:id="@+id/nested_scrollbar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="fill_vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:scrollbars="none" >
        <LinearLayout
            android:id="@+id/nested_scrollbar_linear"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

                <android.support.v7.widget.CardView
                    android:id="@+id/flexible.example.cardview"
                    android:layout_width="match_parent" …
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview android-collapsingtoolbarlayout android-appbarlayout nestedscrollview

6
推荐指数
1
解决办法
6586
查看次数

如何在回收站视图中为卡片添加标题/标题?

我有一个简短的问题。如何在如下图所示的回收站视图上为卡片上的组制作标题。

在此处输入图片说明

非常感谢回答

android android-cardview android-recyclerview cardview

6
推荐指数
1
解决办法
2121
查看次数

Recyclerview:如何将一些帖子与图像混合而没有图像?

我想在同一个回收视图中显示,有些帖子有图片,有些帖子没有图片。

我可以检索所有带有图像和非图像的帖子,但是当用户仅发布文本(无图像)时,我想更改帖子的大小。

我希望像 twitter feed 这样的输出......一些带有图像和没有图像的帖子有自己的大小。

java android android-recyclerview

6
推荐指数
1
解决办法
795
查看次数

使用Gridlayout Manager的Recycler视图

我正在RecyclerViewGridLayout经理一起使用,以便像旅行一样预订座位.

我的问题是当我的列是随机的时候如何自动检测spancount?

我知道spanCount = recyclerViewWidth / singleItemWidth;,但问题是singleItemWidth不同的,因为座位宽度不同.

这是我想要的所需布局:

在此输入图像描述

...但我现在得到这样的东西:

在此输入图像描述

这是我用来安排座位布局的代码:

    gridLayoutManager=new GridLayoutManager(this,totalRows, LinearLayoutManager.VERTICAL,
            false);
    gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
        @Override
        public int getSpanSize(int position) {
            int rows=Integer.parseInt(upperlist.get(position).get("row"));
             return (rows);///(int) (mRecyclerView.getMeasuredWidth()/ 10);
        }
    });
     mRecyclerView.setLayoutManager( gridLayoutManager);
    MyAdapter myAdapter=new MyAdapter(this,gridArray);
Run Code Online (Sandbox Code Playgroud)

... upperlist保持这些值:

 [{cols=8, seatNumber=29U, row=4, zindex=1}, 
  {cols=6,seatNumber=23U, row=4, zindex=1},
  {cols=4,seatNumber=21U,row=4, zindex=1}, 
  {cols=2, seatNumber=11U, row=4, zindex=1}, 
  {cols=0,seatNumber=9U,row=4, zindex=1},

  {cols=8,seatNumber=25U, row=2, zindex=1}, 
  {cols=6,seatNumber=17U, row=2, zindex=1}, 
  {cols=4,seatNumber=13U, row=2, zindex=1}, 
  {cols=2,seatNumber=5U,  row=2, zindex=1}, 
  {cols=10, seatNumber=D2U,row=2, zindex=1}, 
  {cols=0, seatNumber=1U, row=2, …
Run Code Online (Sandbox Code Playgroud)

android gridlayoutmanager android-recyclerview

5
推荐指数
0
解决办法
4123
查看次数

如何在recyclerView中显示不同的布局?

我想显示4种不同类型布局的通知列表.将有4种类型的通知chat_noti,share_noti,coorganizer_noti,invitation_noti.这4种类型有4种不同的布局.我想在recyclerview中展示这一点.

这是我的适配器:

编辑:

List<Notifications> notificationsList;
Context context;
private static final int INVITATION_NOTI = 0;
private static final int CHAT_NOTI = 1;
private static final int SHARE_NOTI = 2;
private static final int COORGANIZER_NOTI = 3;
private int selectedPos = 0;
public NotificationsAdapter(Context context,List<Notifications> notificationsList){
    this.notificationsList = notificationsList;
    this.context = context;
}

@Override
public int getItemViewType(int type) {

    if (type == 0)
    {
        return INVITATION_NOTI;
    }
    else if(type == 1)
    {
        return CHAT_NOTI;
    }
    else if(type == 2)
    {
        return SHARE_NOTI; …
Run Code Online (Sandbox Code Playgroud)

java android android-recyclerview

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

按代码更改Recycler视图项背景颜色

我想更改RecyclerView项目的背景颜色.我想我应该能够在onBindViewHolder方法中做到这一点, 但我无法做到这一点.我只更改了项目的底部边框颜色,但我想更改完整的背景颜色

这就是我想要的

public void onBindViewHolder(InstalledFontViewRecyclerAdapter.ViewHolder holder, int position) {

    if (//Some Condition) {
        holder.itemView.setBackgroundColor(Color.GREY);
    }
    else {
        holder.itemView.setBackgroundColor(Color.RED);
    }
}
Run Code Online (Sandbox Code Playgroud)

我认为这应该产生类似的东西

在此输入图像描述

我得到的就是这个

在此输入图像描述

这是我的RecyclerView Fragment layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent"
    >
    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:id="@+id/installed_recyclerView"
        android:paddingTop="1dp"
        ></android.support.v7.widget.RecyclerView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

这是我的项目布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="3dp"
android:paddingBottom="1dp"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true">

<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/post_card_view"
    android:layout_gravity="center"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    card_view:cardCornerRadius="1dp"
    >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Arial New"
            android:id="@+id/installed_font_name"
            android:textSize="16dp"
            /> …
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview

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

MyAdapter 无法在 android 中投射到 com.google.android.gms.ads.NativeExpressAdView

我一直在使用RecyclerView和 Google Volley 来解析 JSON。然后我添加了谷歌原生广告!

我在此链接上关注教程

所以我确实像谷歌开发者指南一样改变了 RecyclerViewAdapter !

它说列表必须是对象列表(列表)所以我在适配器中更改了这个和其他一些东西!

然后 Android Studio 没有显示错误,我可以启动应用程序。但是当我要使用提到的 RecyclerView 打开 Fragment 时,它崩溃了。

它说:

java.lang.ClassCastException:com.graciaapps.nameoncards.instance.greetoptions.SubOptionOneInstance 无法转换为 com.google.android.gms.ads.NativeExpressAdView

这是 onBindViewHolder 的以下行

NativeExpressAdView adView =(NativeExpressAdView)greetingInstanceList.get(position);
Run Code Online (Sandbox Code Playgroud)

第一个片段.java

NativeExpressAdView adView =(NativeExpressAdView)greetingInstanceList.get(position);
Run Code Online (Sandbox Code Playgroud)

子选项一个适配器.java

package com.cards.adapter.greetoptions;

public class SubOptionOneAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private List<Object> greetingInstanceList;
    Activity activity;
    private String TAG = getClass().getName();
    private static final int MENU_ITEM_VIEW_TYPE = 0;
    private static final int AD_VIEW = 1;

    public SubOptionOneAdapter() {

    }

    public SubOptionOneAdapter(Activity activity, List<Object> greetingInstanceList) {
        this.greetingInstanceList …
Run Code Online (Sandbox Code Playgroud)

java android adapter admob native-ads

5
推荐指数
0
解决办法
1776
查看次数

单击列表项显示更多信息

我不确定这是怎么称呼所以我拍了一张照片.

我想显示一个用户列表,当有人点击其中一个用户时,下面会显示一些细节.再次点击它应该再次隐藏.理想情况下有一些滑动动画.它不应该覆盖列表的其余部分,所以其他一切都必须向下移动.

我希望你明白我的意思.

有人可以告诉我我应该谷歌或有一个例子吗?

在此输入图像描述

java user-interface android

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

分页库-具有多种视图类型的一个回收站

我正在使用项目中的所有Android体系结构组件(Room DB,Live Data等)。目前,我遇到一个问题,即RecyclerView应该使用从Room DB加载的数据并将其与Paging库一起显示。问题是存在多个数据类,这些数据类表示新闻源中的项目并存储在Room中,我需要在一个回收站中显示它们。

有什么办法可以轻松解决吗?例如,我可以创建所有这些类都将使用的接口吗?

android android-recyclerview android-room android-architecture-components android-jetpack

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

如何在聊天应用程序上组织 RecyclerView 与不同类型的消息?

我开发聊天应用程序,有不同类型的消息:简单的文本、图像、文件等。也只有消息(其他,在屏幕左侧)和我的消息(在屏幕右侧)。

现在我对每种类型的消息都有不同的布局:

  • item_message_simple

  • item_my_message_simple

  • 项目消息图像

  • item_my_message_image

  • 项目消息文件

  • 项目我的消息文件

所有这些类型都在 RecyclerView.Adapter 中定义,并且 getItemViewType() 中有许多 if-else 条件

还可以回复和转发具有更复杂布局的消息。如果我想添加新的消息类型,那将是灾难。

那么如何更好地组织呢?也许它应该全部采用一种布局和 2 种类型:MESSAGE、MY_MESSAGE - 以及显示/隐藏部分布局。或者再次输入 2 种类型(MESSAGE、MY_MESSAGE)并在 ViewHolder 中填充所需的子布局。

请任何帮助!

android chat android-layout android-recyclerview

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