我想创建一个布局来浏览类别和子类别,如下所示:
这是针对类别的,我通过在layout中编写.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 );
请让我知道我应该改变什么,以使我的UI正确。谢谢你
发布于 2015-10-19 22:11:50
你应该试试Expandable ListView。我强烈推荐使用它,因为它是内置控件,并且它具有你需要的相同功能。如果你使用RelativeLayout
,你必须管理许多场景,例如解析,项目内部,事件处理;而使用Expandable ListView
,你只需要传递项目层次结构,并使用UI完成。
https://stackoverflow.com/questions/33212014
复制相似问题