I am new in Android Studio and now I am trying to create a game(Puzzle 15). I have already done design and some simple codes but I don't know how to change two buttons postion when they are selected, so please if you know, help me to write code for that! Thank you in advance!
Asked
Active
Viewed 33 times
-1
-
You want to change buttons position or background? – faran.javed Jul 11 '18 at 13:39
1 Answers
0
referring to this question: Set the absolute position of a view just put this code inside the click listener of the button in order to change its position
RelativeLayout rl = (RelativeLayout) findViewById(R.id.my_relative_layout);
Button iv = new Button(this);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(30, 40);
params.leftMargin = 50;
params.topMargin = 60;
rl.addView(iv, params);
note that this works only with relative layout, if you are use something different the process is quite the same.
if you want to change the layout this is the code to put inside the clickListener of the button
Button tiny = (Button)findViewById(R.id.tiny);
tiny.setBackgroundResource(R.drawable.abc);

Giulio Pettenuzzo
- 786
- 1
- 5
- 20