Android: Flip layout horizontally -
say layout has button aligned left, , textview aligned right.
i languages layout displayed is, others, button should on right while text should on left.
is there built-in or simple way dynamically flip layout views?
i create differenet layout , set content view dynamically, rather avoid solution if better suggested.
thanks
here in sample code changing layout on button click can put come login according need likewise
if laguage = "bl bla" call layout1(); else call layout2();
i not creating different layout same layout assigning different layout properties @ dynamically.
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> <button android:id="@+id/btn1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textcolor="@android:color/black" android:background="@drawable/cuadrogris" android:text="button 1" android:textsize="20sp" /> <button android:id="@+id/btn2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textcolor="@android:color/black" android:background="@drawable/cuadrogris" android:layout_below="@id/btn1" android:text="button 2" android:textsize="20sp" /> <button android:id="@+id/btnctrl1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textcolor="@android:color/black" android:background="@drawable/cuadrogris" android:layout_alignparentbottom="true" android:layout_alignparentleft="true" android:text="alignment 1" android:textsize="20sp" /> <button android:id="@+id/btnctrl2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textcolor="@android:color/black" android:background="@drawable/cuadrogris" android:layout_alignparentbottom="true" android:layout_alignparentright="true" android:text="alignment 2" android:textsize="20sp" /> </relativelayout> public class testactivity extends activity { button mbtn1; button mbtn2; button mbtncontroller1; button mbtncontroller2; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.relative_layout_activity); initializecontrols(); } private void initializecontrols() { // todo auto-generated method stub mbtn1 = (button)findviewbyid(r.id.btn1); mbtn2 = (button)findviewbyid(r.id.btn2); mbtncontroller1 = (button)findviewbyid(r.id.btnctrl1); mbtncontroller2 = (button)findviewbyid(r.id.btnctrl2); //i changing layout here on button clicks named(mbtncontroller1 , mbtncontroller2 respectively) //you can same according condition if language = "bla bla" layout else layout mbtncontroller1.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub layout1(); } }); mbtncontroller2.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub layout2(); } }); } private void layout1() { //these layout params in accessing properties of relative layout or linear layout (here using relative layout) relativelayout.layoutparams relativeparamsleft = new relativelayout.layoutparams(layoutparams.wrap_content,layoutparams.wrap_content); relativelayout.layoutparams relativeparamsright = new relativelayout.layoutparams(layoutparams.wrap_content,layoutparams.wrap_content); relativeparamsleft.addrule(relativelayout.align_parent_right);// helps in assging properties of relative layout in xml layout mbtn2.setlayoutparams(relativeparamsleft); // need set these layout params view. relativeparamsright.addrule(relativelayout.align_parent_left); mbtn1.setlayoutparams(relativeparamsright); } private void layout2() { relativelayout.layoutparams relativeparamsleft = new relativelayout.layoutparams(layoutparams.wrap_content,layoutparams.wrap_content); relativelayout.layoutparams relativeparamsright = new relativelayout.layoutparams(layoutparams.wrap_content,layoutparams.wrap_content); relativeparamsleft.addrule(relativelayout.align_parent_left); mbtn2.setlayoutparams(relativeparamsleft); relativeparamsright.addrule(relativelayout.align_parent_right); mbtn1.setlayoutparams(relativeparamsright); } }
Comments
Post a Comment