我想创建一个布局来浏览,看起来像类别和子类别:动态嵌套相对布局
这是分类,我在布局使这个由写.axml那看起来不错。现在,当用户点击类别相同的外观应该在其点击产生的,它是动态创建,但子内容重叠于母公司的内容,看起来像这样:
为了让孩子相对布局我写了下面代码:
RelativeLayout childTaxonomylayout = new RelativeLayout(this);
childTaxonomylayout.Id = Convert.ToInt32(data.Value.Id);
childTaxonomylayout.SetOnClickListener(this);
var param = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);
param.AddRule(LayoutRules.AlignParentBottom);
param.AddRule(LayoutRules.AlignParentLeft);
childTaxonomylayout.LayoutParameters = param;
TextView textViewChild = new TextView(this);
textViewChild.Text = data.Value.Item.Name;
textViewChild.SetPadding(20, 10, 0, 10);
textViewChild.Id = Convert.ToInt32(data.Value.Id);
RelativeLayout.LayoutParams rlp2 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FillParent, RelativeLayout.LayoutParams.WrapContent);
rlp2.AddRule(LayoutRules.AlignParentBottom);
rlp2.AddRule(LayoutRules.AlignParentLeft);
textViewChild.LayoutParameters = rlp2;
childTaxonomylayout.AddView(textViewChild);
if (data.Value.Children.Count != 0) {
var _imgViewClose = new ImageView(this);
_imgViewClose.Id = Convert.ToInt32("123" + data.Value.Id.ToString());
_imgViewClose.SetImageResource(Resource.Drawable.ic_right);
RelativeLayout.LayoutParams rlp1 = new RelativeLayout.LayoutParams(30, 20);
rlp1.AddRule(LayoutRules.AlignParentBottom);
rlp1.AddRule(LayoutRules.AlignParentRight);
childTaxonomylayout.AddView(_imgViewClose);
}
childLayout.AddView(childTaxonomylayout);
请让我知道我应该改变,以使我的用户界面正确。 Thankyou
是的亲爱的,我也通过改变布局来实现这一目标。当我使用嵌套线性布局来代替相对和放置文本和图像到一个更多的线性布局水平时,整个设计得到了正确。你在想那个吗? –