【问题标题】:call textview and imageview in recyclerview在 recyclerview 中调用 textview 和 imageview
【发布时间】:2020-02-12 09:02:20
【问题描述】:

你好,我已经制作了 TextView 的布局(在其中我设置了背景图像)和一个简单的 TextView 视图,并在适配器中膨胀并在回收器视图中显示它们,我可以更改 TextView(带背景)和TextView 作为我在不同的 recyclerview 列表中的愿望,但我也想通过文本的变化来改变 textview 的背景。

这是我输入两个文本视图的arraylist,但我不知道在哪里输入背景图像

wordList.add(new Word("1", "What is neuron?"));
wordList.add(new Word("2", "What is brain?"));
wordList.add(new Word("3", "What is gala?"));
wordList.add(new Word("4", "What is accurd?"));

<TextView android:textColor="@android:color/white"
        android:gravity="center"
        android:id="@+id/circle"
        android:background="@drawable/teal"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_marginLeft="8dp"
        android:text="C"
        android:layout_centerVertical="true"/>
    <TextView
        android:textSize="20sp"
        android:id="@+id/prod_name"
        android:paddingLeft="8dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/circle"
        android:layout_centerVertical="true"/>

【问题讨论】:

  • 您的背景图片存储在服务器上或仅保存在项目中。
  • @YogeshNikamPatil 它在我的项目中
  • 能否请您显示将文本设置为 textview 的代码。
  • 或者显示你想要做的截图。
  • @YogeshNikamPatil 好的;现在我做了三个视图; imageview(用于背景图像);文本视图(前景文本);和 textview 了解详细信息。问题就解决了。实际上;我之前想要的是this,现在看起来也像this

标签: java android android-studio android-recyclerview textview


【解决方案1】:

一开始我想在recyclerView中调用text view的背景图片,并在recyclerview的不同列中根据我的意愿更改背景图片。

但现在我要做的是;我将 textview 和 imageView 作为 textview 的背景并在 recyclerview 中轻松调用它们,现在我可以根据我的意愿在不同的列中更改它们?你明白了吗?

【讨论】:

    【解决方案2】:

    如果您从可绘制资源本地获取背景图像,那么您将不得不像这样修改您的 Word

    Class Word { 
           private String tv1;
           private String tv2;
           private Drawable backgroundImage;
    
               Word(String a, String b, Drawable c){
                  tv1=a; 
                  tv2=b;
                  backgroundImage=c
               }
           }
    

    现在您可以添加这样的图像

    wordList.add(new Word("1", "What is neuron?", 
    getResources().getDrawable(R.drawable.your_img)));
    wordList.add(new Word("2", "What is brain?", 
    getResources().getDrawable(R.drawable.your_img)));
    wordList.add(new Word("3", "What is 
    gala?", getResources().getDrawable(R.drawable.your_img)));
    wordList.add(new Word("4", "What is 
    accurd?", getResources().getDrawable(R.drawable.your_img)));
    

    现在您的 ArrayList 中有背景图像。您可以随意使用它们。

    【讨论】:

      猜你喜欢
      • 2021-08-07
      • 2014-04-26
      • 2014-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多