The code is below but I am having some issues with creating a relative layout(which is a child to a linearLayout). I think that i am creating both textviews correctly(setting up both IDs) and setting the layoutparams for each correctly.
However, the first textview isn’t centered and the 2nd textview isn’t being drawn to the screen(it should be below the menuTitle). Please let me know where i am going wrong here. The LinearLayout, RelativeLayout in the code is inside a main RelativeLayout(which is noted in the setContentView line). All my custom classes do is simply override the draw method to draw a white border around the view. I DO NOT change the layout parameters at all in these subclasses.(i noticed some people were having issues doing this).
As a side note – these are going to be create dynamically so thats the reason for the programmatic route instead of XML. Anyway thanks all for the help in advance!
CustomRelativeLayout subMenuLayout = new CustomRelativeLayout(this);
subMenuLayout.setBackgroundColor(Color.TRANSPARENT);
RelativeLayout.LayoutParams subMenuLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
subMenuLayoutParams.addRule(RelativeLayout.RIGHT_OF, sideMenu.getId());
subMenuLayoutParams.setMargins(0, 0, 200, 0);
subMenuLayout.setLayoutParams(subMenuLayoutParams);
TextView menuItemTitle = new CustomTextView(this);
menuItemTitle.setText("All You Can Eat");
menuItemTitle.setTextSize(30);
menuItemTitle.setBackgroundColor(Color.TRANSPARENT);
menuItemTitle.setTextColor(Color.WHITE);
menuItemTitle.setId(2);
RelativeLayout.LayoutParams menuItemTitleParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
menuItemTitleParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
menuItemTitleParams.setMargins(0, 0, 0, 15);
menuItemTitle.setLayoutParams(menuItemTitleParams);
TextView menuItemDesc = new CustomTextView(this);
menuItemDesc.setText("All you can ribs, chicken, pork and sides you can stomach to eat\nAlso includes dessert!");
menuItemDesc.setTextSize(15);
menuItemDesc.setBackgroundColor(Color.TRANSPARENT);
menuItemDesc.setTextColor(Color.WHITE);
menuItemDesc.setId(3);
RelativeLayout.LayoutParams menuItemDescParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
menuItemDescParams.addRule(RelativeLayout.BELOW, menuItemTitle.getId());
menuItemDesc.setLayoutParams(menuItemDescParams);
subMenuLayout.addView(menuItemTitle);
subMenuLayout.addView(menuItemDesc);
RelativeLayout screenLayout = new RelativeLayout(this);
screenLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
screenLayout.setBackgroundResource(R.drawable.body_bkgd);
screenLayout.addView(sideMenu);
screenLayout.addView(subMenuLayout);
setContentView(screenLayout);
}
I think you need to envelop your
TextViews in a vertically orientedLinearLayout. Add both of yourTextViews to a LinearLayout instead of theRelativeLayout, then add theLinearLayoutto theRelativeLayoutwith the position parameters you want. Here’s an example: