View overlap with RelativeLayout on Android 1.5

I have a problem with overlapping views in RelativeLayout on Android 1.5 ... Everything works fine on Android 1.6 and above.

I understand that Android 1.5 has some problems with RelativeLayout, but I could not find anything in StackOverflow or the Android Starter Group for my specific problem.

My layout consists of four sections, each of which consists of a TextView, a gallery, and another TextView vertically aligned:

Launch applications
Recent Applications
Services
The processes

When all four sets of these items are displayed, everything works fine. However, my application allows the user to indicate that some of them are not displayed. If the user disables Launch Applications, Recent Applications, or Services, the remaining sections suddenly overlap.

Here is my code for the layout. I'm not sure what I'm doing wrong. When the user turns off the section display, I use the visibility parameter View.GONE:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center_vertical" android:layout_gravity="center_vertical" android:background="@null" > <!-- Running Gallery View Items --> <TextView style="@style/TitleText" android:id="@+id/running_gallery_title_text_id" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:paddingLeft="1sp" android:paddingRight="10sp" android:text="@string/running_title" /> <Gallery android:id="@+id/running_gallery_id" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/running_gallery_title_text_id" android:spacing="5sp" android:clipChildren="false" android:clipToPadding="false" android:unselectedAlpha=".5" /> <TextView style="@style/SubTitleText" android:id="@+id/running_gallery_current_text_id" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/running_gallery_id" android:gravity="center_horizontal" /> <!-- Recent Gallery View Items --> <TextView style="@style/TitleText" android:id="@+id/recent_gallery_title_text_id" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/running_gallery_current_text_id" android:gravity="left" android:paddingLeft="1sp" android:paddingRight="10sp" android:text="@string/recent_title" /> <Gallery android:id="@+id/recent_gallery_id" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/recent_gallery_title_text_id" android:spacing="5sp" android:clipChildren="false" android:clipToPadding="false" android:unselectedAlpha=".5" /> <TextView style="@style/SubTitleText" android:id="@+id/recent_gallery_current_text_id" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/recent_gallery_id" android:gravity="center_horizontal" /> <!-- Service Gallery View Items --> <TextView style="@style/TitleText" android:id="@+id/service_gallery_title_text_id" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/recent_gallery_current_text_id" android:gravity="left" android:paddingLeft="1sp" android:paddingRight="10sp" android:text="@string/service_title" /> <Gallery android:id="@+id/service_gallery_id" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/service_gallery_title_text_id" android:spacing="5sp" android:clipChildren="false" android:clipToPadding="false" android:unselectedAlpha=".5" /> <TextView style="@style/SubTitleText" android:id="@+id/service_gallery_current_text_id" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/service_gallery_id" android:gravity="center_horizontal" /> </RelativeLayout> 

I skipped the xml for the Processes section in a (somewhat futile) attempt to keep this shorter ...

What can I do to make this work in Android 1.5? I don't think this is just a matter of reordering views in xml, because it works fine when everything is displayed.

+4
source share
1 answer

Two possible solutions:

  • Try setting the element height to 0 or 1 px and visibility for INVISIBLE instead of GONE.
  • Wrap each gallery / TextView in a LinearLayout set to wrap_height and set above / belows on the layouts instead of peeps. Then set the sub-elements to View.GONE, leaving the line layouts used for relative positioning still visible, but with a height of 0 wrapped.

The idea with any solution is to make sure you never position something relative to the View.GONE view; I suspect that the source of the error you encountered.

If I can ask, though ... why do I need to use RelativeLayout at all? From what I see at a glance, everything here fits perfectly into the vertical LinearLayout and actually seems conceptually simpler for this layout.

+4
source

Source: https://habr.com/ru/post/1305979/


All Articles