xml - What's wrong with this dynamic layout? [Android] -
i need create dynamically linearlayout represent xml code:
<linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#ddd" android:orientation="vertical" android:padding="1dp" > <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" > </linearlayout> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#fff" android:orientation="horizontal" android:paddingbottom="26dp" android:paddingtop="26dp" > <linearlayout android:layout_width="160dp" android:layout_height="match_parent" android:layout_weight="1" android:background="#fff" > <imageview android:id="@+id/imageview04" android:layout_width="48dp" android:layout_height="48dp" android:layout_gravity="top" android:layout_marginleft="32dp" android:layout_margintop="4dp" android:background="#eee" /> </linearlayout> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="#fff" android:orientation="vertical" > <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top" android:gravity="top" android:paddingbottom="4dp" android:paddingleft="16dp" android:text="name of event" android:textsize="22sp" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:paddingleft="16dp" android:text="group of event" android:textcolor="#aaa" android:textsize="16sp" /> </linearlayout> </linearlayout> </linearlayout>
but problem wrote code have no idea why after debugging application thing see name of event.
here's code:
public class event extends linearlayout{ private linearlayout globalcontener; private linearlayout contener; private linearlayout avatarbox; private linearlayout contentbox; private textview eventname; private textview eventgroup; private imageview avatar; private linearlayout.layoutparams globalcontenerparams = new linearlayout.layoutparams(layoutparams.match_parent, layoutparams.match_parent); private linearlayout.layoutparams contenerparams = new linearlayout.layoutparams(layoutparams.match_parent, layoutparams.wrap_content); private linearlayout.layoutparams avatarboxparams = new linearlayout.layoutparams(160, layoutparams.match_parent, 1.0f); private linearlayout.layoutparams contentboxparams = new linearlayout.layoutparams(layoutparams.match_parent, layoutparams.match_parent); private linearlayout.layoutparams eventnameparams = new linearlayout.layoutparams(layoutparams.wrap_content, layoutparams.wrap_content); private linearlayout.layoutparams eventgroupparams = new linearlayout.layoutparams(layoutparams.wrap_content, layoutparams.wrap_content); private linearlayout.layoutparams avatarparams = new linearlayout.layoutparams(48, 48); public event(context context){ super(context); // design of global contener globalcontenerparams.setmargins(0, 0, 0, 32); globalcontener = new linearlayout(context); globalcontener.setbackgroundcolor(0xdddddd); globalcontener.setpadding(1, 1, 1, 1); globalcontener.setorientation(linearlayout.vertical); globalcontener.setlayoutparams(globalcontenerparams); // design of contener contener = new linearlayout(context); contener.setbackgroundcolor(0xffffff); contener.setpadding(0, 26, 0, 26); contener.setorientation(linearlayout.horizontal); contener.setlayoutparams(contenerparams); // design of avatar box avatarbox = new linearlayout(context); avatarbox.setbackgroundcolor(0xffffff); avatarbox.setlayoutparams(avatarboxparams); // design of contet box contentbox = new linearlayout(context); contentbox.setorientation(linearlayout.vertical); contentbox.setbackgroundcolor(0xffffff); contentbox.setlayoutparams(contentboxparams); // design of avatar avatarparams.gravity = gravity.top; avatarparams.setmargins(32, 4, 0, 0); avatar = new imageview(context); avatar.setbackgrounddrawable(const.avatarimg); avatar.setlayoutparams(avatarparams); // design of event name eventnameparams.gravity = gravity.top; eventname = new textview(context); eventname.setgravity(gravity.top); eventname.setpadding(16, 0, 0, 4); eventname.settextsize(22); eventname.settext("sprawdzian z języka polskiego"); eventname.setlayoutparams(eventnameparams); // design of event group eventgroup = new textview(context); eventgroup.setgravity(gravity.center); eventgroup.setpadding(16, 0, 0, 0); eventgroup.settextsize(16); eventgroup.settextcolor(0xaaaaaa); eventgroup.settext("4ia technikum Łączności w krakowie"); eventgroup.setlayoutparams(eventgroupparams); // packing boxes avatarbox.addview(avatar); contentbox.addview(eventgroup); contentbox.addview(eventname); contener.addview(avatarbox); contener.addview(contentbox); globalcontener.addview(contener); // adding view addview(globalcontener); } }
is here can me this?
set main linearlayout orientation vertical , then
set contentboxparams weight 1f
private linearlayout.layoutparams contentboxparams = new linearlayout.layoutparams(layoutparams.match_parent, layoutparams.match_parent,1.0f);
then put this
contentbox.addview(eventname);
before
contentbox.addview(eventgroup);
and replace 0xffffff
0xffffffff
Comments
Post a Comment