android - Dynamically set layout_below doesn't take effect -
i have checkbox layout_below
1 view. when view's visibility set gone, i'm trying set checkbox below one. can't work, code below, tip?
if (certificate.gettype() == verifiedcertificate.student_card) { anchorschoolview.setvisibility(view.visible); imgschool.setvisibility(view.visible); txtschool.setvisibility(view.visible); txtschoolname.setvisibility(view.visible); relativelayout.layoutparams lp = (relativelayout.layoutparams) cbquestion.getlayoutparams(); lp.addrule(relativelayout.below, r.id.txtschoolname); cbquestion.setlayoutparams(lp); } else { anchorschoolview.setvisibility(view.gone); imgschool.setvisibility(view.gone); txtschool.setvisibility(view.gone); txtschoolname.setvisibility(view.gone); relativelayout.layoutparams lp = (relativelayout.layoutparams) cbquestion.getlayoutparams(); lp.addrule(relativelayout.below, r.id.txtdoctype); cbquestion.setlayoutparams(lp); }
update: xml file requested
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content"> <button android:id="@+id/btnotherside" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentend="true" android:layout_alignparentright="true" android:layout_below="@+id/toppanel" android:layout_marginright="8dp" android:layout_margintop="8dp" android:text="@string/view_other_side" /> <com.devspark.robototextview.widget.robototextview android:id="@+id/txtdoctype" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginleft="16dp" android:layout_margintop="16dp" android:text="@string/doc_id_card" android:textsize="16sp" app:textstyle="normal" app:textweight="light" /> <imageview android:id="@+id/imgdocfile" android:layout_width="match_parent" android:layout_height="200dp" android:layout_below="@+id/txtdoctype" android:layout_margintop="20dp" android:adjustviewbounds="true" android:src="@drawable/img_id_card" /> <imageview android:id="@+id/icondoc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_below="@+id/imgdocfile" android:layout_marginleft="16dp" android:layout_margintop="24dp" android:src="@drawable/ic_credit_card" /> <view android:id="@+id/anchordoc" android:layout_width="1dp" android:layout_height="1dp" android:layout_aligntop="@+id/icondoc" android:layout_marginleft="20dp" android:layout_margintop="8dp" android:layout_torightof="@+id/icondoc" android:background="@android:color/transparent" /> <textview android:id="@+id/txtnumber" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/anchordoc" android:layout_alignleft="@+id/anchordoc" android:text="@string/document_id_number" /> <textview android:id="@+id/txtdocnumbervalue" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/anchordoc" android:layout_below="@+id/anchordoc" android:text="0123456" /> <imageview android:id="@+id/icondate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_aligntop="@+id/icondoc" android:layout_centerhorizontal="true" android:src="@drawable/ic_calendar" /> <view android:id="@+id/anchordate" android:layout_width="3dp" android:layout_height="3dp" android:layout_aligntop="@+id/icondate" android:layout_marginleft="20dp" android:layout_margintop="8dp" android:layout_torightof="@+id/icondate" android:background="@android:color/transparent" /> <textview android:id="@+id/txtregodate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/anchordate" android:layout_alignleft="@+id/anchordate" android:text="@string/rego_day" /> <textview android:id="@+id/txtregovalue" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/anchordate" android:layout_below="@+id/anchordate" android:text="01/06/2010" /> <imageview android:id="@+id/iconschool" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_below="@+id/txtdocnumbervalue" android:layout_marginleft="16dp" android:layout_margintop="30dp" android:src="@drawable/ic_school" /> <view android:id="@+id/anchorschool" android:layout_width="1dp" android:layout_height="1dp" android:layout_aligntop="@+id/iconschool" android:layout_marginleft="20dp" android:layout_margintop="8dp" android:layout_torightof="@+id/iconschool" android:background="@android:color/transparent" /> <textview android:id="@+id/txtschool" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/anchorschool" android:layout_alignleft="@+id/anchorschool" android:text="@string/school_name" /> <textview android:id="@+id/txtschoolname" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/anchorschool" android:layout_below="@+id/anchorschool" android:text="school name" /> <com.devspark.robototextview.widget.robotocheckbox android:id="@+id/cbsecondquesion" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/txtschoolname" android:layout_marginbottom="8dp" android:layout_marginleft="10dp" android:layout_marginright="16dp" android:layout_margintop="8dp" android:text="@string/confirm_doc_is_genuine" app:textstyle="normal" app:textweight="medium" /> </relativelayout>
update 2: work, set wrong view id
Comments
Post a Comment