如何以编程方式在FrameLayout底部设置LinearLayout?

时间:2013-07-08 09:42:32

标签: android android-linearlayout android-framelayout

我有这段代码:

         FrameLayout game = new FrameLayout(this);
         LinearLayout gameWidgets = new LinearLayout (this);
         game.addView(gameWidgets);

如何在FrameLayout的底部设置LinearLayout?

2 个答案:

答案 0 :(得分:16)

试试这个,

FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
    LayoutParams.WRAP_CONTENT,
    LayoutParams.WRAP_CONTENT);

params.gravity = Gravity.BOTTOM;

game.addView(GameWidgets, params); 

答案 1 :(得分:4)

使用此代码:

FrameLayout.LayoutParams p = new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.WRAP_CONTENT,
            FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM
                    | Gravity.CENTER_HORIZONTAL);
game.addView(GameWidgets, p);