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>
4

2 回答 2

1

您需要为LayoutParams您的LinearLayout. 请参考这里的帖子检查 FilterAnimationonAnimationEnd()布局移动的方法

于 2013-07-09T07:25:19.263 回答
1

您可以尝试将 LinearLayout 与 RelativeLayout 交换。

然后,当您想让某些视图低于/高于另一个视图时,您可以使用它:

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);
于 2013-07-03T07:47:54.817 回答