水平滚动中的图像和文本查看(动态)

时间:2014-09-28 10:07:44

标签: android

我希望在水平滚动视图图像中以及每个图像下方我想要一个文本视图。我动态地想要这个。到目前为止,我有按钮背景图像,我使用方法设置文本的文本,它的工作原理。但是,我想分别从图像编辑文本,因为我想要一个不同的文本颜色,以便可见。这是我的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);
}

1 个答案:

答案 0 :(得分:0)

具有与您期望的图像和文本分开的xml文件。 然后使用inflate

动态添加
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);
}