android - How to make all child view at vertical center of a horizontal LinearLayout which gravity is center_vertical after add views to it -
here horizontal linearlayout
, set it's gravity center_vertical
, add 2 views linearlayout
, height of first view bigger other, result second view align top of first view, not @ vertical center of linearlayout
. how make child view @ vertical center, ideas?
here code:
context context = getactivity(); mpicturecontainer = new linearlayout(context); mpicturecontainer.setbackgroundcolor(0xffffffff); mpicturecontainer.setgravity(gravity.center_vertical); mpicturecontainer.setorientation(linearlayout.horizontal); int leftrightmargin = getresources().getdimensionpixelsize(r.dimen.leftrightmargin); mpicturecontainer.setpadding(leftrightmargin, 0, leftrightmargin, 0); //... maddpicbtn = new imageview(context); maddpicbtn.setlayoutparams(new linearlayout.layoutparams(utils.dip2px(77f), utils.dip2px(77f))); maddpicbtn.setscaletype(scaletype.center_crop); maddpicbtn.setimagedrawable(statelistfactory.createstatelistdrawable(r.drawable.add_prs, -1, r.drawable.add)); //... mpicturecontainer.removeallviews(); arraylist<string> pictures = (arraylist<string>) data.getserializableextra("pictures"); int size = pictures.size(); (int = 0; < size; i++) { string path = pictures.get(i); final view view = layoutinflater.from(getactivity()).inflate(r.layout.status_pic_item, mpicturecontainer, false); view.settag(path); imageview imageview = (imageview) view.findviewbyid(r.id.picture); imageview delpicbtn = (imageview) view.findviewbyid(r.id.delpicbtn); delpicbtn.setimagedrawable(statelistfactory.createstatelistdrawable(r.drawable.del_prs, -1, r.drawable.del)); delpicbtn.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { mpicturecontainer.removeview(view); if (mpicturecontainer.getchildcount() < 4 && maddpicbtn.getparent() != mpicturecontainer) { mpicturecontainer.addview(maddpicbtn); } } }); mpicturecontainer.addview(view, i); imageloader.loadimage(imageview, "file://" + path); } if (mpicturecontainer.getchildcount() < 4) { mpicturecontainer.addview(maddpicbtn); }
and here layout status_pic_item
:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="81dp" android:layout_height="81dp" android:layout_marginright="3dp" > <imageview android:id="@+id/picture" android:layout_width="77dp" android:layout_height="77dp" android:layout_alignparentbottom="true" android:scaletype="centercrop" /> <imageview android:id="@+id/delpicbtn" android:layout_width="20dp" android:layout_height="20dp" android:layout_alignparentright="true" android:clickable="true" /> </relativelayout>
and here screenshot:
Comments
Post a Comment