标签:android relativelayout overlap
我在Android 1.5上的RelativeLayout中存在重叠视图的问题…在Android 1.6及更高版本上一切正常.
我知道Android 1.5在RelativeLayout上有一些问题,但我无法在StackOverflow或android初学者组中找到任何关于我的具体问题的内容.
我的布局由四个部分组成,每个部分由TextView,Gallery和另一个垂直对齐的TextView组成:
运行应用程序
最近的应用
服务
流程
当所有这四个项目都显示出来时,一切正常.但是,我的应用程序允许用户指定其中一些不显示.如果用户关闭“运行应用程序”,“最近的应用程序”或“服务”,则其余部分会突然重叠.
这是我的布局代码.我不确定我做错了什么.当用户关闭部分的显示时,我使用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>
我省略了进程部分的xml(有点徒劳)试图让它更短……
我该怎么做才能在Android 1.5中使用它?我不认为这只是重新排序xml中的视图的问题,因为它在显示所有内容时都能正常工作.
解决方法:
两种可能的解决方
>尝试将元素的高度设置为0或1像素,并将可见性设置为INVISIBLE而不是GONE.
>将LinearLayout中的每个Gallery / TextView设置为wrap_height,并在布局而不是子视图上设置上/下.然后将子元素设置为View.GONE,使用于相对定位的线性布局仍然可见但包裹高度为0.
任何解决方案的想法是确保你永远不会相对于View.GONE的视图定位某些东西;我怀疑这是你遇到的bug的来源.
如果我可以问,虽然……为什么你甚至需要在这里使用RelativeLayout?从我所看到的一目了然,这里的所有内容都可以很好地适应垂直的LinearLayout,事实上这种安排似乎在概念上更简单.
标签:android,relativelayout,overlap 来源: https://codeday.me/bug/20190627/1300315.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。