我面臨着視圖之間的空間問題。使用LinerLayout並動態添加視圖(ImageViews)到線性佈局。如何在佈局中重疊圖像瀏覽
我想調整imageview之間的空間。我希望他們有一個重疊 - 當添加一個新的視圖。
目前藍色回地面施加到突出兩個線性佈局。
代碼圖像視圖添加到現有佈局
dealerImages= (LinearLayout) findViewById(R.id.dealerImages);
dealerImages.setBackgroundColor(Color.BLUE);
ImageView view = new ImageView(BlackJack.this);
view.setImageResource(R.drawable.back);
dealerImages.addView(view);
我每次添加一個新的觀點 - 我想指定的舊觀點的相對位置。我希望新視圖從佈局中最後一個視圖的中心開始。
請讓我知道你是否需要任何額外的細節。請建議我是否需要使用其他佈局來簡化操作。
編輯 - 在這裏
playerLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.MATCH_PARENT);
dealerLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.MATCH_PARENT);
private void dealTwoCardsEach(){
player.addCard(hit());
ImageView imageView = new ImageView(BlackJack.this);
imageView.setImageResource(getResourceId(player.getFirstCard()));
playerImages.addView(imageView, player.getCards().size()-1);
dealer.addCard(hit());
imageView = new ImageView(BlackJack.this);
imageView.setImageResource(getResourceId(dealer.getFirstCard()));
dealerImages.addView(imageView);
player.addCard(hit());
if(player.getCount() == 21)
player.setBlackJack(true);
imageView = new ImageView(BlackJack.this);
imageView.setImageResource(getResourceId(player.getSecondCard()));
updateMarginForPlayer(); // updating start margin
playerImages.addView(imageView, player.getCards().size()-1, playerLayoutParams);
dealer.addCard(hit());
}
private void updateMarginForPlayer(){
playerLayoutParams.setMarginStart(playerLayoutParams.getMarginStart()+100);
}
發佈的代碼請不我沒有設置第一卡播放器的任何保證金。 我可以看到這兩個卡,直到這裏。以0開始餘量,並用100
private void handleHit(){
Card c1 = hit();
player.addCard(c1);
ImageView imageView = new ImageView(this);
imageView.setImageResource(getResourceId(c1));
updateMarginForPlayer();
playerImages.addView(imageView, playerLayoutParams);
}
開始餘量在「命中」按鈕點擊所述第二圖像的第一圖像是當handleHit()被調用。並且添加的新圖像使得從第2個到當前視圖的所有圖像都不可見。我只能看到第一個和最後一個(最新添加的)。
謝謝。這似乎工作。但現在,在指定的邊界添加新視圖後,我無法看到它下面的視圖。我只能看到第一個和最新的。是否有一個屬性需要在添加子視圖之前設置爲始終可見。 – Lochan
它們不可見,因爲它們可能在最後一個視圖下方,您可以發佈您的代碼,以便我可以爲您編輯它! – MadScientist
我用代碼編輯了原始問題。請看一下。 – Lochan