【问题标题】:Change size layout in code in android在android中更改代码中的大小布局
【发布时间】:2012-08-30 00:33:59
【问题描述】:

我有一个关于调整布局大小的问题。这是我的活动:

@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。

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    我不知道您的要求是什么,但我更喜欢在 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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多