帮助与Android的LinearLayout或RelativeLayout的 [英] Help with Android LinearLayout or RelativeLayout
问题描述
我需要以编程方式创建两个观点(因为我需要访问的美景之一的OnDraw)。出于某种原因,不管我做什么的意见添加到内容查看,他们不露面垂直堆叠,一是低于其他。
我可以把它就好使用使用RelativeLayout的布局定位的XML,但与XML,我不能创建一个视图对象,并重载OnDraw的方法做的。
我在做什么错误的方案办法,以及如何解决这个问题?
的LinearLayout mLinearLayout; 公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState); //创建在其中添加ImageView的一个的LinearLayout
mLinearLayout =新的LinearLayout(本); TextView的电视=新的TextView(本);
tv.setBackgroundColor(0xff333333);
tv.setText(请输入您的会员号:);
tv.setLayoutParams(新ViewGroup.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT)); DrawableView I =新DrawableView(本);
i.layout(0,40,0,0);
i.setLayoutParams(新Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT)); mLinearLayout.addView(电视);
mLinearLayout.addView(I,300,300);
的setContentView(mLinearLayout);
}
您可以线性布局对象的方向设置为垂直
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);
}
you can set the orientation of the linear layout object to vertical
这篇关于帮助与Android的LinearLayout或RelativeLayout的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!