1

I've got problem with setting visibility to relative layout. I have part of big layout in relativelayout and below that next TextView. But in my code, when myRelativeLayout.setVisibility(View.GONE); is called, TextView which is below that did not appear. I tried several ways to rearange layout, but i need that textview under it. Thanks

My XML:

<merge xmlns:android="http://schemas.android.com/apk/res/android" >
    <ScrollView
        android:id="@+id/scrollView_liab_ra_flipper_04"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <RelativeLayout
            android:id="@+id/linearLayout_liab_ra_flipper_04"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/someTextView"
                android:text="Something" />

            <!-- This relative layout should be removable -->
            <RelativeLayout
                android:id="@+id/vg_liab_ra_04_flipper_car_container_visible"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/someTextView" >

                <TextView
                    android:id="@+id/tv_1"
                    style="@style/WhiteFormText"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="15dp"
                    android:layout_marginTop="2dp"
                    android:text="@string/licence_plate_counter" >
                </TextView>

                <EditText
                    android:id="@+id/et_1"
                    style="@style/WhiteFormField"
                    android:layout_below="@+id/tv_1"
                    android:hint="@string/licence_plate_hint" >
                </EditText>
            </RelativeLayout>

            <!-- This textview is not visible if relative layout is gone -->
            <TextView
                android:id="@+id/tv_liab_ra_04_flipper_mandat"
                style="@style/WhiteFormTextHint"
                android:layout_below="@+id/vg_liab_ra_04_flipper_car_container_visible"
                android:layout_marginBottom="15dp"
                android:text="@string/mandatory_field" >
            </TextView>
        </RelativeLayout>

    </ScrollView>
</merge>

Java Code:

 private void hideCar() {      

   if (!accident.getParticipant(0)) {
        rlCarContainer.setVisibility(View.GONE);

    } else {
        rlCarContainer.setVisibility(View.VISIBLE);

    }

}
4

1 回答 1

1

做你想做的最简单的方法是使用LinearLayout而不是你的根RelativeLayout..在你隐藏你想要的方式后,子视图将重新对齐RelativeLayout..如果你不想要那样,你可以android:layout_alignWithParentIfMissing此处使用文档。这不会完全按照您的意愿工作,但它可能会帮助您解决问题:)。TextView

于 2012-06-24T21:10:26.407 回答