How to change the position/view of relativelayout in android -


i have layout has 3 relativelayouts placed follows.

  • relativelayout1 -> other widgets , switch
  • relativelayout2 -> 2 imagebuttons placed vertically
  • relativelayout3 -> 2 buttons placed vertically

by default state of switch in off state.

what want is

  1. when switch in off state relativelayout3 should placed or should overlap relativelayout2, i.e 3rd layout should come @ position 2
  2. when switch enabled (i.e in on state), relativelayout2 should visible , relativelayout3 should come below it.

below layout

<relativelayout  xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/bckgrnd_4">      <textview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:textappearance="?android:attr/textappearancemedium"         android:text="task name"         android:id="@+id/textview5"         android:layout_alignbottom="@+id/edittext"         android:layout_alignstart="@+id/textview6" />      <edittext         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:id="@+id/edittext"         android:hint="@string/hint_name"         android:layout_margintop="37dp"         android:layout_alignparenttop="true"         android:layout_toendof="@+id/textview7" />       <button         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="set"         android:id="@+id/button5"         style="@style/btnstylebeige"         android:layout_margintop="37dp"         android:layout_below="@+id/textview5"         android:layout_alignstart="@+id/switch1" />     <textview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:textappearance="?android:attr/textappearancemedium"         android:text="set location"         android:id="@+id/textview6"         android:layout_alignbottom="@+id/button5"         android:layout_tostartof="@+id/edittext" />      <textview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:textappearance="?android:attr/textappearancemedium"         android:text="always alert me"         android:id="@+id/textview7"         android:layout_centervertical="true"         android:layout_alignparentstart="true" />      <switch         android:layout_width="wrap_content"         android:layout_height="wrap_content"         style="@style/btnstylebeige"         android:id="@+id/switch1"         android:layout_aligntop="@+id/textview7"         android:layout_alignend="@+id/edittext" />      <relativelayout         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:id="@+id/relative2"         android:layout_margintop="37dp"         android:layout_below="@+id/switch1"         android:layout_alignparentstart="true">          <imagebutton             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/imagebutton3"             android:src="@drawable/cal"             style="@style/btnstylebeige"             android:layout_marginstart="42dp"             android:layout_alignparenttop="true"             android:layout_alignparentstart="true" />          <imagebutton             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/imagebutton4"             style="@style/btnstylebeige"             android:src="@drawable/alert"             android:layout_marginstart="67dp"             android:layout_alignbottom="@+id/imagebutton3"             android:layout_toendof="@+id/imagebutton3" />      </relativelayout>      <relativelayout         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:id="@+id/relative3"         android:layout_alignparentbottom="true"         android:layout_centerhorizontal="true">          <button             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:text="add task"             style="@style/btnstylebeige"             android:id="@+id/button6" />          <button             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:text="cancel"             style="@style/btnstylebeige"             android:layout_alignparenttop="true"             android:layout_toendof="@+id/button6"             android:layout_marginstart="37dp" />      </relativelayout>  </relativelayout> 

please me...

you can put listener switch , toggle visibility of layout based on whether switch on or off. example,

    switch s = (switch) findviewbyid(r.id.switch1);      s.setoncheckedchangedlistener (this);      ... }  public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) {      relativelayout relative2 = (relativelayout) findviewbyid(r.id.relative2);     relative2.setvisibility(ischecked ? view.gone:view.visible);  } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -