我有一个layout_below
一个视图的复选框。然后,当该视图的可见性设置为已消失时,我尝试将该复选框设置为低于另一个。我无法正常工作,我的代码在下面,任何提示?谢谢
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);
}
更新:按要求提供的XML文件
<?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>
更新2:它确实有效,我只是设置了错误的视图ID