滚动视图不显示视图
Scrollview not showing views
我有一个 recyclerview,我可以在其中显示我的数据。 recyclerviewitem 的一部分是滚动视图。
所以我用数据填充recyclerview 并在holder 中设置图片和文本。我也想给那里的scrollview加图片
override fun onBindViewHolder(holder: SchritteViewHolder, position: Int) {
val current = schritte[position]
holder.rezeptePicView.setImageDrawable( ContextCompat.getDrawable(context,current.alg.bild))
var text = ""
for( zut in zutatenforSchritte[position]) {
val imageViewzut = ImageView(this.context)
val textView = TextView(this.context)
imageViewzut.setImageDrawable(ContextCompat.getDrawable(context,zut.bild))
textView.text = zut.zutname
text =text + zut.zutname
holder.scrollViewSchritte.addView(imageViewzut)
holder.scrollViewSchritte.addView(textView)
}
holder.rezepteItemView.text = current.alg.text + " " + current.sp.temperatur + " " +current.sp.zeit +" " + current.sp.sonst +text
}
数据在那里,因为我可以在文本中填充它,图片和文本在那里,但滚动视图保持为空。
我不知道为什么滚动视图保持空白。因此,如果您知道可能是什么原因,提示会很好。
我认为您应该指定您使用的 LayoutParams 的实现。
此外,您只能在滚动视图中显示 一个 项。
holder.scrollViewSchritte.layoutParams(LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT))
所以,scrollview waws the wrn gway to go。我添加了另一个只显示图标的 recyclerview。
所以外部 Recyclerview 看起来像这样:
class SchritteSmallListAdapterJustShow internal constructor(
context: Context
): RecyclerView.Adapter<SchritteSmallListAdapterJustShow.SchritteViewHolder>(){
private val inflater: LayoutInflater = LayoutInflater.from(context)
private var schritte = emptyList<SpezSchrittWithAlg>()
val contextfu = context
private var zutatenforSchritte :MutableList<List<ZutatenData>> =emptyList<List<ZutatenData>>().toMutableList()
inner class SchritteViewHolder(itemView : View): RecyclerView.ViewHolder(itemView){
val rezepteItemView: TextView = itemView.findViewById(R.id.textSmallschritt)
val rezeptePicView: ImageView = itemView.findViewById(R.id.imageViewschritt)
var recycler: RecyclerView = itemView.findViewById(R.id.recyclerviewforIcons)
val adapter = ZutatenIconShowAdapter(contextfu)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SchritteViewHolder {
val itemView = inflater.inflate(R.layout.recyclerview_schritte, parent, false)
return SchritteViewHolder(itemView)
}
override fun onBindViewHolder(holder: SchritteViewHolder, position: Int) {
val current = schritte[position]
holder.rezeptePicView.setImageDrawable( ContextCompat.getDrawable(contextfu,current.alg.bild))
holder.rezepteItemView.text = current.alg.text + " " + current.sp.temperatur + " " +current.sp.zeit +" " + current.sp.sonst
holder.recycler.adapter = holder.adapter
holder.recycler.layoutManager = LinearLayoutManager(contextfu, RecyclerView.HORIZONTAL, false)
holder.recycler.layoutMode
holder.adapter.setZutaten(zutatenforSchritte[position])
}
internal fun setSchritte(rez : List<SpezSchrittWithAlg>){
schritte = rez
notifyDataSetChanged()
}
internal fun setZutatenliste(zutaten : MutableList<List<ZutatenData>>){
zutatenforSchritte = zutaten
}
override fun getItemCount(): Int =schritte.size
}
内部 Recyclerview 如下所示:
class ZutatenIconShowAdapter internal constructor(
context: Context
): RecyclerView.Adapter<ZutatenIconShowAdapter.ZutatenViewHolder>(){
private val inflater: LayoutInflater = LayoutInflater.from(context)
private var zutaten = emptyList<ZutatenData>()
private val context = context
inner class ZutatenViewHolder(itemView : View): RecyclerView.ViewHolder(itemView){
val rezeptePicView: ImageView = itemView.findViewById(R.id.smallIconview)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ZutatenViewHolder {
val itemView = inflater.inflate(R.layout.recyclerview_just_icon, parent, false)
return ZutatenViewHolder(itemView)
}
override fun onBindViewHolder(holder: ZutatenViewHolder, position: Int) {
val current = zutaten[position]
holder.rezeptePicView.setImageDrawable( ContextCompat.getDrawable(context,current.bild))
}
internal fun setZutaten(zutats: List<ZutatenData>){
zutaten= zutats
notifyDataSetChanged()
}
override fun getItemCount(): Int =zutaten.size
}
这让我得到了我想要的结果:
我有一个 recyclerview,我可以在其中显示我的数据。 recyclerviewitem 的一部分是滚动视图。
所以我用数据填充recyclerview 并在holder 中设置图片和文本。我也想给那里的scrollview加图片
override fun onBindViewHolder(holder: SchritteViewHolder, position: Int) {
val current = schritte[position]
holder.rezeptePicView.setImageDrawable( ContextCompat.getDrawable(context,current.alg.bild))
var text = ""
for( zut in zutatenforSchritte[position]) {
val imageViewzut = ImageView(this.context)
val textView = TextView(this.context)
imageViewzut.setImageDrawable(ContextCompat.getDrawable(context,zut.bild))
textView.text = zut.zutname
text =text + zut.zutname
holder.scrollViewSchritte.addView(imageViewzut)
holder.scrollViewSchritte.addView(textView)
}
holder.rezepteItemView.text = current.alg.text + " " + current.sp.temperatur + " " +current.sp.zeit +" " + current.sp.sonst +text
}
数据在那里,因为我可以在文本中填充它,图片和文本在那里,但滚动视图保持为空。
我不知道为什么滚动视图保持空白。因此,如果您知道可能是什么原因,提示会很好。
我认为您应该指定您使用的 LayoutParams 的实现。
此外,您只能在滚动视图中显示 一个 项。
holder.scrollViewSchritte.layoutParams(LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT))
所以,scrollview waws the wrn gway to go。我添加了另一个只显示图标的 recyclerview。
所以外部 Recyclerview 看起来像这样:
class SchritteSmallListAdapterJustShow internal constructor(
context: Context
): RecyclerView.Adapter<SchritteSmallListAdapterJustShow.SchritteViewHolder>(){
private val inflater: LayoutInflater = LayoutInflater.from(context)
private var schritte = emptyList<SpezSchrittWithAlg>()
val contextfu = context
private var zutatenforSchritte :MutableList<List<ZutatenData>> =emptyList<List<ZutatenData>>().toMutableList()
inner class SchritteViewHolder(itemView : View): RecyclerView.ViewHolder(itemView){
val rezepteItemView: TextView = itemView.findViewById(R.id.textSmallschritt)
val rezeptePicView: ImageView = itemView.findViewById(R.id.imageViewschritt)
var recycler: RecyclerView = itemView.findViewById(R.id.recyclerviewforIcons)
val adapter = ZutatenIconShowAdapter(contextfu)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SchritteViewHolder {
val itemView = inflater.inflate(R.layout.recyclerview_schritte, parent, false)
return SchritteViewHolder(itemView)
}
override fun onBindViewHolder(holder: SchritteViewHolder, position: Int) {
val current = schritte[position]
holder.rezeptePicView.setImageDrawable( ContextCompat.getDrawable(contextfu,current.alg.bild))
holder.rezepteItemView.text = current.alg.text + " " + current.sp.temperatur + " " +current.sp.zeit +" " + current.sp.sonst
holder.recycler.adapter = holder.adapter
holder.recycler.layoutManager = LinearLayoutManager(contextfu, RecyclerView.HORIZONTAL, false)
holder.recycler.layoutMode
holder.adapter.setZutaten(zutatenforSchritte[position])
}
internal fun setSchritte(rez : List<SpezSchrittWithAlg>){
schritte = rez
notifyDataSetChanged()
}
internal fun setZutatenliste(zutaten : MutableList<List<ZutatenData>>){
zutatenforSchritte = zutaten
}
override fun getItemCount(): Int =schritte.size
}
内部 Recyclerview 如下所示:
class ZutatenIconShowAdapter internal constructor(
context: Context
): RecyclerView.Adapter<ZutatenIconShowAdapter.ZutatenViewHolder>(){
private val inflater: LayoutInflater = LayoutInflater.from(context)
private var zutaten = emptyList<ZutatenData>()
private val context = context
inner class ZutatenViewHolder(itemView : View): RecyclerView.ViewHolder(itemView){
val rezeptePicView: ImageView = itemView.findViewById(R.id.smallIconview)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ZutatenViewHolder {
val itemView = inflater.inflate(R.layout.recyclerview_just_icon, parent, false)
return ZutatenViewHolder(itemView)
}
override fun onBindViewHolder(holder: ZutatenViewHolder, position: Int) {
val current = zutaten[position]
holder.rezeptePicView.setImageDrawable( ContextCompat.getDrawable(context,current.bild))
}
internal fun setZutaten(zutats: List<ZutatenData>){
zutaten= zutats
notifyDataSetChanged()
}
override fun getItemCount(): Int =zutaten.size
}
这让我得到了我想要的结果: