我希望创建一个类别和子类别浏览的布局,如下图所示:
这是针对类别的,并通过在布局中编写.axml文件来实现。现在,当用户单击类别时,应生成相同的外观,但它是动态生成的,但子内容重叠到父内容并且看起来像这样:
为了创建一个相对子布局,我编写了以下代码:
![enter image description here](https://istack.dev59.com/WvY3E.webp)
![enter image description here](https://istack.dev59.com/1HHo0.webp)
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 );
请告诉我应该如何更改才能使我的用户界面正确。谢谢。