【问题标题】:Margin layout programmatically is not working以编程方式进行的边距布局不起作用
【发布时间】:2013-12-17 17:01:58
【问题描述】:

谁能解决我的问题(垂直菜单没有边距/空间)?看我的代码链接http://pastebin.com/zzdY3QQR

【问题讨论】:

  • 我只是在程序中给布局备注,但如果我打开备注,它不起作用(没有边距)

标签: android layout margin


【解决方案1】:

试试这个..

LinearLayout menuvertical = (LinearLayout) findViewById(R.id.menuvertical);
    for (int i = 0; i < arrseparate.size(); i++) {
        TextView menucategory = new TextView(getBaseContext());

        LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        llp.setMargins(50, 0, 0, 0);
        menucategory.setText(arrseparate.get(i).toString());
        menucategory.setTextSize(25);
        menucategory.setTextColor(Color.WHITE);
        menucategory.setBackgroundResource(R.layout.bordermenu);
        final int j = i;
        menucategory.setGravity(Gravity.CENTER_HORIZONTAL);

        if (j != 0) {
            menucategory.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    OtherClass.setCategory(arrseparate.get(j).toString());

                    Global.MainActivity.finish();
                    Intent MyIntent = new Intent(getBaseContext(),
                            ViewProduct.class);
                    startActivity(MyIntent);
                }
            });
        }
        menuvertical.addView(menucategory, llp);
    }

【讨论】:

  • @AgoengLauw 看到 addView(menucategory, llp);
  • @AgoengLauw 你试试看有没有结果。
猜你喜欢
  • 2015-08-22
  • 1970-01-01
  • 2017-01-17
  • 1970-01-01
  • 2012-07-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多