Issue
I'm having trouble with some code I've set up that allows me to move an imageView's drawable to another imageView simply by clicking on the two imageViews (one with source image and then destination imageView) in succession.
The goal is to simulate a chessboard.
My starting display is the following:
And after I click the leftmost pawn then click the square directly in front of it, the result is the following. You'll see that the target imageView (first column 3rd row) is losing its horizontal boundary definition and expanding across the entire tableRow:
Now, I'm also resetting tags along with the drawables in each square but I'd imagine that the issue stems from the way in which I'm getting and setting the drawables.
My code is as follows:
int selectedId = getResources().getIdentifier(selectedSquare, "id", getPackageName());
ImageView sourceSquare = (ImageView) findViewById(selectedId);
Drawable sourceDrawable = sourceSquare.getDrawable();
ImageView targetSquare = (ImageView) findViewById(R.id.s20);
targetSquare.setImageDrawable(sourceDrawable);
My guess is that the sourceDrawable
variable I'm creating somehow grabs too much or too little information and when I move that drawable into the new imageView targetSquare
this destroys my formatting.
Solution
You can give the new ImageView the source LayoutParams of the origin:
targetSquare.setLayoutParams(sourceSquare.getLayoutParams);
Answered By - yshahak
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.