Help with Android LinearLayout or RelativeLayout
Posted
by PeEll
on Stack Overflow
See other posts from Stack Overflow
or by PeEll
Published on 2010-06-03T05:01:05Z
Indexed on
2010/06/03
5:04 UTC
Read the original article
Hit count: 470
I need to create two views programmatically (because I need to access the ondraw of one of the views). For some reason, no matter what I do to add the views to the contentview, they don't show up vertically stacked, one below the other.
I can do it just fine using the XML using a RelativeLayout and layout positioning, but with the XML I can't create a view object and overload the ondraw method.
What am I doing wrong with the programmatic approach, and how do I solve this problem?
LinearLayout mLinearLayout;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create a LinearLayout in which to add the ImageView
mLinearLayout = new LinearLayout(this);
TextView tv = new TextView(this);
tv.setBackgroundColor(0xff333333);
tv.setText("Enter your member number:");
tv.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
DrawableView i = new DrawableView(this);
i.layout(0,40,0,0);
i.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
mLinearLayout.addView(tv);
mLinearLayout.addView(i,300,300);
setContentView(mLinearLayout);
}
© Stack Overflow or respective owner