我想創建一個佈局來瀏覽,看起來像類別和子類別:動態嵌套相對佈局
這是分類,我在佈局使這個由寫.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
是的親愛的,我也通過改變佈局來實現這一目標。當我使用嵌套線性佈局來代替相對和放置文本和圖像到一個更多的線性佈局水平時,整個設計得到了正確。你在想那個嗎? –