質問には、私はランダムな位置で表示したい画像ビュー(カードのデッキ)が52個あります。ランダムな位置でレイアウトに画像ビューを追加する最良の方法
私は現在、この持っている:これは今のところ動作しますが、後に、私は特定の場所ですべてのカードを表示する必要がありますし、それだけのマージンですべてを配置する私には思えるいけない
for (Card card : deck.getAll()) {
ImageView iv = new ImageView(this);
RelativeLayout.LayoutParams lParams = new RelativeLayout.LayoutParams(57, 105);
if (random) {
lParams.leftMargin = (int)Math.ceil(Math.random()*(metrics.widthPixels - 57));
lParams.topMargin = (int)Math.ceil(Math.random()*(metrics.heightPixels - 105));
} else {
//if (metrics.widthPixels < ((i + 1) * 57)) {i = 0;++j;}
if (i > 12) {i = 0;++j;}
lParams.leftMargin = i*60;
lParams.topMargin = j*107;
++i;
}
iv.setRotation((float)Math.ceil(Math.random()*(360)));
iv.setId(card.getInt());
layout.addView(iv, lParams);
を。
ありがとうございました。
私はちょっとした作業の後、解決策を見つけました。 http://stackoverflow.com/a/35406696/3741769 – Ahsanwarsi