2014-09-28 64 views
0

我想要在水平滚动查看图像和每个图像下面我想要一个文本视图。我想动态地。到现在为止,我已经有图像背景的按钮,我使用文本方法设置文本,它的工作原理。但是,我想要从图像中分别编辑文本,因为我想为文本显示不同的颜色。这是我的xml:图像和文本在水平滚动查看(动态)

<HorizontalScrollView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 
      <LinearLayout 
       android:id="@+id/ImagesHsw" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal"> 
      </LinearLayout> 
</HorizontalScrollView> 

更新:

vi=  ((LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.actor,null); 
    Button b = (Button)findViewById(R.id.actorImage); 
    TextView text = (TextView)findViewById(R.id.actorName); 
    for (int i=0; i<actors; i++) { 
      b.setBackgroundResource(R.drawable.actor); 
      b.setLayoutParams(new ViewGroup.LayoutParams(160,150)); 
      text.setText(i); 
      actorsScrollView.addView(vi); 
} 
+0

ü可以用[Horizo​​ntalVariableListView]尝试将其添加(https://github.com/sephiroth74/Horizo​​ntalVariableListView) – kId 2014-09-29 16:53:25

+0

我曾经想过水平ListView和我已经找到了这个帖子的http:/ /www.dev-smart.com/archives/34,但我有进口问题。 – user3607469 2014-09-29 20:07:22

+0

您是否正确添加了库? – kId 2014-09-30 03:16:53

回答

0

有形象和为u期待文本单独的XML文件。 然后动态使用膨胀

for (int i = 0; i < actors; i++) { 
    View vi = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.actor, null); 
    Button b = (Button) vi.findViewById(R.id.actorImage); 
    TextView text = (TextView) vi.findViewById(R.id.actorName); 

    b.setBackgroundResource(R.drawable.actor); 
    text.setText(i); 

    actorsScrollView.addView(vi); 
} 
+0

不幸的是,它不起作用。该程序在'urLL.addView(vi)'中崩溃。它显示此消息:指定的孩子已经有一个父母。您必须先调用子对象的父对象的removeView()。 – user3607469 2014-09-29 16:14:14

+0

发布您的代码。 – 2014-09-29 16:16:36

+0

我只能添加评论。作为一个评论,我不认为你会明白,因为我不能改变线。 – user3607469 2014-09-29 16:25:15