0

Expected Result

In onClick() callback method, programmatically set a new position for linear layout.

Problem

Neither the linear layout nor the button can be placed to a new place.

Source Code

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>
Community
  • 1
  • 1
George
  • 3,384
  • 5
  • 40
  • 64

2 Answers2

1

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);
dasdasd
  • 1,971
  • 10
  • 45
  • 72
  • Thank you @dasdasd, but what I need here is to moving (or _tranlating_) the linear layout horizontally to another place. Any idea about that? – George Jul 03 '13 at 07:58
  • what do you mean another place? you want to make it in another layout? I think that using RelativeLayout is the easy way. – dasdasd Jul 03 '13 at 09:09
  • Alright, let me explain it: in the beginning the content view (a linear layout) is on top of the slide menu (a scroll view), both of these two are in a frame layout so that the overlapped layout can be placed there. Then clicking on the upper left corner of the content view, the content view slides rightward and show the hidden menu behind. – George Jul 03 '13 at 09:16
1

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

Community
  • 1
  • 1
Muhammad Babar
  • 8,084
  • 5
  • 39
  • 56