Android - image overlay (playing cards)

I am trying to make game cards in my game overlapped so that I can only see the first half of the card, and the other half is covered with the next game card. The only map that needs to be fully visible will be the last / rightmost map.

I used the following code with both the framelayout function and relativelayout to no avail. can anyone suggest some suggestions?

public int shouldShow(int numberOfCards, int card, int id) { if(card == -1) hide(id); else { findViewById(id).setBackgroundDrawable(deckimages[card]); //findViewById(id).offsetLeftAndRight(findViewById(id).getWidth()* numberOfCards / 2); show(id); //findViewById(id).setPadding(findViewById(id).getWidth()* numberOfCards / 2, 0,0,0); return numberOfCards+1; } return numberOfCards; } 

I tried using fill and offset methods, none of which worked for me. but I also noticed that the getwidth () and getmeasuredwidth () methods return 0.

are there any suggestions for using the layout that I should use, and why are the getwidth arent functions working?

xml code below ... there would be more images than this, but this is what I tested

 <RelativeLayout android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/RelativeLayout1"> <ImageView android:id="@+id/imageView2" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView> <ImageView android:id="@+id/imageView3" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView> </RelativeLayout> 
+6
source share
2 answers

I was stuck on this for ages and after 4 hours was messing around with code and Googling. I finally figured out the solution, and it's pretty simple.

All you have to do is align the next card at the top and left of the previous card. This will make the second card be placed on top of the card earlier. Then set leftMargin to “push” the card from top to right, creating a partial overlap effect.

Here is my code (programmatically):

 for(int i=0; i<hand.size();i++){ int c = hand.get(i).getCardResource(); ib = new ImageButton(this); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); params.addRule(RelativeLayout.ALIGN_TOP, i-1); params.addRule(RelativeLayout.ALIGN_LEFT,i-1); params.leftMargin= 40; ib.setImageResource(c); ib.setClickable(true); ib.setPadding( 3, 3, 3, 3); ib.setId(i); ib.setLayoutParams(params); ll.addView(ib); } 
+8
source

You can provide presentation boundaries deliberately inconsistent with image size and use ScaleType for Imageview: http://developer.android.com/reference/android/widget/ImageView.ScaleType.html . For example, android:scaleType="fitStart"

+1
source

Source: https://habr.com/ru/post/900214/


All Articles