标签: android-recyclerview

滚动到NestedScrollView中的recyclerview中的位置?

没有NestedScrollView可以使用,但是当我使用该滚动到无法使用RecyclerView的位置时

下面是xml代码;

<android.support.design.widget.CoordinatorLayout     
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/co_ordinate_layout"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:background="@color/light_gray">

 <android.support.v4.widget.NestedScrollView    
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:layout_marginTop="@dimen/dimen_55"
  android:fillViewport="true">
<LinearLayout
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:descendantFocusability="blocksDescendants"
    android:orientation="vertical">

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

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

            <ImageView
                android:id="@+id/img_resturant"
                android:layout_width="match_parent"
                android:layout_height="150dp"
                android:background="@drawable/products_offers"
                android:scaleType="fitXY" />

            <LinearLayout
                android:id="@+id/llTransparent"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/dimen_20"
                android:focusableInTouchMode="true"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/tvRestaurantName"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="@dimen/dimen_15"
                    android:textColor="@color/white"
                    android:textSize="@dimen/sp_20" />

                <TextView
                    android:id="@+id/tvAddress"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_gravity="center"
                    android:layout_toRightOf="@+id/ivTime"
                    android:textColor="@color/white"
                    android:textSize="@dimen/sp_14" />


                <TextView
                    android:id="@+id/tvTime"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_gravity="center"
                    android:textColor="@color/white"
                    android:textSize="@dimen/sp_14" />

                <View
                    android:layout_width="match_parent"
                    android:layout_height="0.5dp"
                    android:layout_marginLeft="@dimen/_20sdp"
                    android:layout_marginRight="@dimen/_20sdp"
                    android:layout_marginTop="@dimen/_10sdp"
                    android:background="@color/white" />

                <LinearLayout
                    android:layout_width="match_parent" …
Run Code Online (Sandbox Code Playgroud)

android android-studio android-recyclerview

0
推荐指数
1
解决办法
2148
查看次数

我找不到FirebaseRecyclerAdapter

我是Android Studio的新手,正在尝试创建一个卡片视图,该视图将使用Firebase适配器托管数据,但找不到吗?我希望将代码放入我的onStart方法中,以便我可以填充卡,但是FirebaseRecyclerAdapter却没有出现(我收到它找不到符号的错误)。我已经添加了依赖项和导入,但是仍然没有出现。帮助将不胜感激!

编辑 这是我的依赖项的图像

android firebase android-recyclerview firebase-realtime-database firebaseui

0
推荐指数
1
解决办法
461
查看次数

回收器视图中的动态图像高度

我想使用Glide加载具有动态高度的图像。我有一个ImageView,其高度为wrap_content,宽度为match_parent。回收器视图首次加载时。第一幅图像的高度大于其余图像的高度。当我向下滚动视图进行回收时,我的较大高度的图像可以很好地加载且没有任何像素化;当我滚动回到顶部的第一张较大图像时,它得到了像素化的感觉。由于图像变得像素化。我不想在recyclerview上使用setRecyclable(false)。这是实现

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

    <ImageView
        android:id="@+id/drc_imageView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:scaleType="centerCrop"
        android:src="@color/OFF_WHITE" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

用于加载图像

GlideApp
                .with(context)
                .asBitmap()
                .fitCenter()
                .load(absoluteHomeList.get(position - 1).getDynamic_card_url())
                .into(holder.dynamicImageView);
Run Code Online (Sandbox Code Playgroud)

这是供参考的图像 在第一个图像中,当未回收图像时,图像正确加载而没有像素化

在第二张图片中,我上下滚动了回收站视图,第一张图片被像素化

android android-recyclerview android-glide

0
推荐指数
1
解决办法
1402
查看次数

将卡刷到最喜欢的项目

当我偶然发现这个视频时,我正在查看Google的Material文档.它显示了一个卡片项目,可以向右滑动以收藏项目.

我想镜像这种行为但多次失败.我能找到的所有库和教程都是关于swipe-to-delete.我试图将两个视图堆叠在一起,其中顶部的一个应该被刷,以便下面的一个可见.我尝试用这个来实现这个ItemTouchHelper,但是这个类似乎只能促进swipe-to-deletemove重新排序列表操作.

如何实现此滑动操作?

animation android android-cardview android-recyclerview

0
推荐指数
1
解决办法
842
查看次数

如何使用RecyclerView完成Adapter类的活动

我正在尝试Recyclerview使用代码单击项目时完成适配器类的活动

public void onBindViewHolder(@NonNull CountryCodeAdapter.CountryViewHolder holder, int position{
    CountryModel countryMode = countryModels.get(position);
    final String cCode = countryModel.getName();
    holder.llcountryCode.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(v.getContext(),RegisterActivity.class);                        
            i.putExtra("countryCode", cCode);
            v.getContext().startActivity(i);
            ((AppCompatActivity)context).finish();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

也尝试过这个但是没用

((Activity)context).finish();
Run Code Online (Sandbox Code Playgroud)

我得到这个错误:

cannot be cast to android.support.v7.app.AppCompatActivity
Run Code Online (Sandbox Code Playgroud)

android adapter android-recyclerview

0
推荐指数
1
解决办法
1063
查看次数

android kotlin-如何将单击侦听器添加到RecyclerView适配器

我是kotlin的新手,这是我的适配器代码,可以正常工作,并且我没有问题,现在,我需要为其实现点击监听器,这是我的代码:

class CategoryAdapter(val context: Context,val list: List<CategoryItems>): RecyclerView.Adapter<CategoryAdapter.ViewHolder>() {
var typeface: Typeface? = Func.getTypeFace(context)

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
    var catRow=list.get(position)

    holder?.tvTitle.text = catRow.name
    holder?.tvTitle.setTypeface(typeface)
    Glide.with(context).load(Const.BaseUrl+"Opitures/"+  catRow.icon_name).into(holder?.imgCat);
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
    val v = LayoutInflater.from(parent?.context).inflate(R.layout.category_item, parent, false)
    return ViewHolder(v);
}

override fun getItemCount(): Int {
    return list.size
}

class ViewHolder(itemView: View): RecyclerView.ViewHolder(itemView){
    val tvTitle = itemView.findViewById<TextView>(R.id.tv_cat_title)
    val imgCat = itemView.findViewById<ImageView>(R.id.img_cat)
}
}
Run Code Online (Sandbox Code Playgroud)

我想添加点击侦听器,我曾经在实现点击侦听器的viewholder类中这样做

如何在Kotlin中做到这一点?我绑了很多路但没有成功

android kotlin android-recyclerview

0
推荐指数
1
解决办法
3711
查看次数

无法智能地强制转换为“ GridLayoutManager”,因为“ ViewManager”是可变属性,到那时可能已更改

“无法智能地强制转换为“ GridLayoutManager”,因为“ ViewManager”是一个可变属性,可能此时已更改”

是AndroidStudio在尝试向我的RecyclerView添加分频器时显示的错误。

PixelsFragment.kt

class PixelsFragment : Fragment() {

    private lateinit var recyclerView: RecyclerView
    private lateinit var viewManager: RecyclerView.LayoutManager
    private lateinit var viewAdapter: RecyclerView.Adapter<*>
    private var listener: OnFragmentInteractionListener? = null
    private lateinit var pixels: List<Pixel>

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        var numberOfColumns = 1

        viewManager = GridLayoutManager(this.context, numberOfColumns)
        viewAdapter = MyRecyclerViewAdapter(pixels)


        recyclerView = view!!.findViewById<RecyclerView>(R.id.RVJanuary).apply {
            setHasFixedSize(true)
            layoutManager = viewManager
            adapter = viewAdapter
            addItemDecoration(DividerItemDecoration(recyclerView.context, viewManager.getOrientation())) //Error on this line, underlining viewManager
        }


    }
}
Run Code Online (Sandbox Code Playgroud)

我找到了这个答案,它说这是可能引起的,因为变量可能恰好在null执行该行时出现,然后它们提供了3个解决方案。但是,据我所知, …

android kotlin android-recyclerview

0
推荐指数
1
解决办法
159
查看次数

处理片段中的空回收查看器

我正在尝试制作一个应用程序,在其中使用Recycle View和Volley从服务器获取数据,并且还使用了Navigation抽屉和片段,一切正常,但是当在recycle-view上没有数据时,我想显示一个通知,例如“没有数据!”我多次搜索互联网,但没有找到合适的解决方案,或者因为我完全是初学者,所以无法正确理解。

波纹管是我的Java文件

1.适配器

package com.eworld.myapplication;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.squareup.picasso.Picasso;

import java.util.List;

public class ExchangesAdapter extends RecyclerView.Adapter<ExchangesViewHolder> {

    private List<ExchangesSetterGetter>exchangeList;
    private Context context;

    public ExchangesAdapter(List<ExchangesSetterGetter> exchangeList, Context context) {
        this.exchangeList = exchangeList;
        this.context = context;
    }

    @NonNull
    @Override
    public ExchangesViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view=LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.cardlayout,viewGroup,false);
        ExchangesViewHolder viewHolder=new ExchangesViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ExchangesViewHolder exchangesViewHolder, int i) {
        String status="";


        final ExchangesSetterGetter exchangesPosition=exchangeList.get(i);

            if (exchangesPosition.getStatus().equals("1")) …
Run Code Online (Sandbox Code Playgroud)

java android android-volley android-recyclerview

0
推荐指数
1
解决办法
87
查看次数

XML/android: How to make white underline for RecyclerView Item?

I need to make a little white line under my every recycler view item (from left to right corner), not for any particular element in that item, but for the whole item. (that way it's easier for a user to see which elements are in this particular item, and where another item starts)

Here is my item layout:

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/_5sdp"
    app:cardCornerRadius="0dp"
    app:cardElevation="0dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorPrimaryDark">

        <TextView
            android:id="@+id/nameView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Mike"
            android:textColor="@color/colorAccent"
            android:textSize="@dimen/_21sdp" …
Run Code Online (Sandbox Code Playgroud)

xml android view android-recyclerview

0
推荐指数
1
解决办法
120
查看次数

回收者视图不尊重列表项的边距

它应该是什么样子 -

工作室样本

看起来怎么样——

安卓截图

列表项.xml -

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView 
    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="wrap_content"
    app:cardBackgroundColor="@color/card_background"
    android:layout_marginVertical="5dp"
    android:layout_marginHorizontal="10dp"
    app:cardCornerRadius="8dp">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/is_app_or_web_image_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/card_spacing"
            android:padding="@dimen/image_padding"
            app:layout_constraintBottom_toBottomOf="@id/delete_image_view"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toTopOf="@id/delete_image_view"
            tools:src="@drawable/is_website_icon_24" />

        <TextView
            android:id="@+id/service_name_text_view"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginHorizontal="@dimen/card_spacing"
            android:text="@string/service_name"
            android:textSize="16sp"
            app:layout_constraintBottom_toBottomOf="@id/delete_image_view"
            app:layout_constraintLeft_toRightOf="@id/is_app_or_web_image_view"
            app:layout_constraintRight_toLeftOf="@id/edit_image_view"
            app:layout_constraintTop_toTopOf="@id/delete_image_view" />


        <androidx.appcompat.widget.AppCompatImageButton
            android:id="@+id/delete_image_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/card_spacing"
            android:layout_marginEnd="@dimen/card_spacing"
            android:background="@color/card_foreground"
            android:padding="@dimen/image_padding"
            android:src="@drawable/ic_baseline_delete_20"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />


        <androidx.appcompat.widget.AppCompatImageButton
            android:id="@+id/show_image_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="@dimen/card_spacing"
            android:background="@color/card_foreground"
            android:padding="@dimen/image_padding"
            android:src="@drawable/ic_baseline_show_20"
            app:layout_constraintBottom_toBottomOf="@id/delete_image_view"
            app:layout_constraintRight_toLeftOf="@id/delete_image_view"
            app:layout_constraintTop_toTopOf="@id/delete_image_view" />


        <androidx.appcompat.widget.AppCompatImageButton
            android:id="@+id/edit_image_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="@dimen/card_spacing"
            android:background="@color/card_foreground"
            android:padding="@dimen/image_padding"
            android:src="@drawable/ic_baseline_edit_20"
            app:layout_constraintBottom_toBottomOf="@id/delete_image_view"
            app:layout_constraintRight_toLeftOf="@id/show_image_view"
            app:layout_constraintTop_toTopOf="@id/delete_image_view" /> …
Run Code Online (Sandbox Code Playgroud)

xml android kotlin android-recyclerview

0
推荐指数
1
解决办法
691
查看次数