I have a screen where I display five buttons inside a Linearlayout vertically. this linear layout is inside a relative layout and aligned to parent right. Now I need that when any button is clicked it should shift leftwards while others remain at the original position. I am trying to give left margin to the button on being clicked but the problem is all the buttons are shifting and not only that one.
这里是法典
final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layoutParams.rightMargin = 20;
mColorButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
fillDataList(1);
mIsClicked = true;
//[start] setting the colour of button
mColorButton.setBackgroundResource(R.drawable.yellow_stick) ;
mColorButton.setLayoutParams(layoutParams);
mPatternButton.setBackgroundResource(R.drawable.brown_stick);
mDistributionButton.setBackgroundResource(R.drawable.brown_stick);
mShapeButton.setBackgroundResource(R.drawable.brown_stick);
mLesionButton.setBackgroundResource(R.drawable.brown_stick);
//[end] setting the colour of button
}
});