簡體   English   中英

以編程方式無法使用邊距布局

[英]Margin layout programmatically is not working

有人可以解決我的問題嗎(垂直菜單沒有邊距/空間)? 看到我的代碼鏈接http://pastebin.com/zzdY3QQR

嘗試這個..

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);
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM