简体   繁体   中英

Margin layout programmatically is not working

can somebody solve my problem (there is no margin/space for vertical menu) ? see my code link http://pastebin.com/zzdY3QQR

Try this..

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM