Reputation: 3619
In onClick()
callback method, programmatically set a new position for linear layout.
Neither the linear layout nor the button can be placed to a new place.
Main.java > public class MainActivity extends Activity {}
Neither of the following two code snippet works.
(1)
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(480, 800); // unit is pixel
params.leftMargin = 420; // Shift 420 pixels from left screen border
params.rightMargin = -60; // Exceed 60 pixels from right screen border
mLinearLayout.setLayoutParams(params);
(2)
Button mButtonMenu = (Button) findViewById(R.id.button_menu);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(80, 55); // unit is pixel
params.leftMargin = 420; // unit is pixel
params.rightMargin = -60; // unit is pixel
mButtonMenu.setLayoutParams(params);
activity_main.xml
> elements structure
<FrameLayout
<ScrollView <!-- The menu -->
</ScrollView>
<LinearLayout <!-- The content -->
<Button />
<TextView />
</LinearLayout>
</FrameLayout>
Upvotes: 0
Views: 3107
Reputation: 8134
You need to set the LayoutParams
for the movement of your LinearLayout
. Kindly refer the post Here check Class FilterAnimation and method onAnimationEnd()
for the movement of layouts
Upvotes: 1
Reputation: 2031
You can try swap LinearLayout with RelativeLayout.
And then when you want to make some view to be under/above another you can use this:
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.BELOW, R.id.YOUR_VIEW_ID);
YOUR_VIEW.setLayoutParams(lp);
Upvotes: 1