0

我怎样才能让 imageViews 彼此并排而不是在彼此之上?

    public void deckButtonOnClick(View v) {
    ImageView imageView = new ImageView(getApplicationContext());
    imageView.setImageResource(DECK.takeCard());
    imageView.setAdjustViewBounds(true);
    imageView.setLayoutParams(PARAMS);
    imageView.setTag("0");
    imageView.setOnClickListener(new MyOnClickListener());

    ((RelativeLayout) findViewById(R.id.innerRelativeLayout)).addView(imageView);

}

谢谢!

4

2 回答 2

0

在 xml 中,使用 android:layout_toRightOf=id。

在代码中,将 imageView.setLayoutParams() 与 RelativeLayout.LayoutParams 一起使用并使用 params.addRule(RelativeLayout.RIGHT_OF, id);

于 2013-02-11T19:27:45.283 回答
0

选项 1:使用orientation="horizo​​ntal",将卡片的容器重新设计为LinearLayout 而不是RelativeLayout。

选项2:使用RelativeLayout,您需要为您创建的每个imageView 提供一个ID(可能在每次创建一个计数器时增加一个计数器并将其附加到ID)。然后,当您创建 PARAMS 变量时,您可以添加一条规则以与前一个 ImageView 的右侧对齐。

PARAMS = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
PARAMS.addRule(RelativeLayout.RIGHT_OF, R.id.imageView1);
imageView.setLayoutParams(PARAMS);
于 2013-02-11T19:28:59.600 回答