imageview中的Recryler如何使不可见

Posted

技术标签:

【中文标题】imageview中的Recryler如何使不可见【英文标题】:Recryler in imageview how to make invisible 【发布时间】:2021-10-15 00:09:09 【问题描述】:

我该如何解决这个问题? 我想在 Imageview 中进行 recylerview 使 INVISIBLE 但它不起作用 我的代码如下 对不起我的英语不好:) 这个动作很多地方都找不到源

class CevaplarRecylerAdapter(
                         private val username: ArrayList<String>,
                         private val comment: ArrayList<String>,
                         )
:RecyclerView.Adapter<CevaplarRecylerAdapter.ViewHolder>() 

override fun onCreateViewHolder(
    parent: ViewGroup,
    viewType: Int
): CevaplarRecylerAdapter.ViewHolder 
    val inflater=LayoutInflater.from(parent.context)
    val view =inflater.inflate(R.layout.answer_layout, parent, false)
    return ViewHolder(view)


override fun onBindViewHolder(holder: CevaplarRecylerAdapter.ViewHolder, position: Int) 
    holder.UsernameText?.text=username[position]
    holder.LoadAnswerText?.text=comment[position]


override fun getItemCount(): Int 
    return username.size


inner class ViewHolder(itemView:View):RecyclerView.ViewHolder(itemView)

    var UsernameText:TextView?=null
    var LoadAnswerText:TextView?=null
    @SuppressLint("ResourceType")
    var kontrol:ImageView=itemView.findViewById(R.drawable.cevap)

    init 
        LoadAnswerText=itemView.findViewById(R.id.LoadAnswerTexttv)
        UsernameText=itemView.findViewById(R.id.UsernameTexttv)
        kontrol.visibility = View.INVISIBLE; // ı want to this view make Invisiable          
    

interface OnItemClickListener 


【问题讨论】:

【参考方案1】:

在您的 ViewHolderfindViewById 中,您的 imageView 的 id 不是可绘制对象

改变这一行

 @SuppressLint("ResourceType")
 var kontrol:ImageView=itemView.findViewById(R.drawable.cevap)

var kontrol:ImageView=itemView.findViewById(R.id.yourImageViewId)

【讨论】:

【参考方案2】:

找到了

class CevaplarRecylerAdapter(
                         private val username: ArrayList<String>,
                         private val comment: ArrayList<String>,
                         private val check:Boolean
                         )
:RecyclerView.Adapter<CevaplarRecylerAdapter.ViewHolder>() 

override fun onCreateViewHolder(
    parent: ViewGroup,
    viewType: Int
): CevaplarRecylerAdapter.ViewHolder 
    val inflater=LayoutInflater.from(parent.context)
    val view =inflater.inflate(R.layout.answer_layout, parent, false)
    return ViewHolder(view)


override fun onBindViewHolder(holder: CevaplarRecylerAdapter.ViewHolder, position: Int) 
    holder.UsernameText?.text=username[position]
    holder.LoadAnswerText?.text=comment[position]
    var a=true
    if (a==true)
        Picasso.get().load("https://firebasestorage.googleapis.com/v0/b/egitimnoktasilast.appspot.com/o/images%2F06b57525-0f40-4f86-9fae-8dc6082aab7e.jpg?alt=media&token=5183e857-2252-48b3-bbca-f96a0517ddce").into(holder.photo)
    


override fun getItemCount(): Int 
    return username.size




inner class ViewHolder(itemView:View):RecyclerView.ViewHolder(itemView)

    var UsernameText:TextView?=null
    var LoadAnswerText:TextView?=null
       var photo:ImageView?=null


    init 
        LoadAnswerText=itemView.findViewById(R.id.LoadAnswerTexttv)
        UsernameText=itemView.findViewById(R.id.UsernameTexttv)
        photo=itemView.findViewById(R.id.Rightimage)
        Visibility(check)
    

     fun Visibility(check: Boolean)
        if (check==true)
            photo!!.visibility=View.VISIBLE
        
         else
            photo!!.visibility=View.INVISIBLE
        
    





interface OnItemClickListener 


【讨论】:

【参考方案3】:

你需要在drawable的地方添加你的imageview的id,如下所示-

替换这个

   var kontrol:ImageView=itemView.findViewById(R.drawable.cevap)

有了这个

   var kontrol:ImageView=itemView.findViewById(R.id.yourimageviewid)

【讨论】:

以上是关于imageview中的Recryler如何使不可见的主要内容,如果未能解决你的问题,请参考以下文章

如何使不和谐机器人自动发送消息?

Android 中的可见性消失

RecyclerView 中的 VideoView 大小错误

如何将 videoView 与 imageView 和 recyclerView 一起制作动画?

如何将我的标题放在 ImageView 的顶部

如何获取 iCarousel 当前可见视图?