更改android中代码的大小布局

时间:2012-09-05 10:01:27

标签: android android-layout

我对调整大小布局有疑问。这是我的活动:

@Override
protected void onCreate(Bundle savedInstanceState) {


    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    requestWindowFeature(Window.FEATURE_ACTION_BAR);
    setContentView(R.layout.log_in);


}

如何在此活动中设置R.layout.log_in的大小?我希望设置大小为400x300,但活动不是xml。

1 个答案:

答案 0 :(得分:0)

我不知道你的要求是什么,但我更喜欢在xml上设置维度(如果它们被认为是固定的)。

无论如何,this可能很有用。

链接中使用的代码:

// Gets linearlayout
LinearLayout layout = (LinearLayout)findViewById(R.id.numberPadLayout);
// Gets the layout params that will allow you to resize the layout
LayoutParams params = layout.getLayoutParams();
// Changes the height and width to the specified *pixels*
params.height = 300;
params.width = 400;