Android ViewGroup 裁剪不起作用
为什么 android:clipChildren="false" 不起作用?我想实现与 CSS Overflow:visible 相同的效果,以便子视图即使位于父布局之外也是可见的。我尝试了类似的方法,尽管 Eclipse 中的图形布局显示了正确的行为,但在手机上却不起作用。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#0000FF"
android:clipChildren="false"
android:clipToPadding="false" >
<RelativeLayout
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:background="#FF0000"
android:clipChildren="false"
android:clipToPadding="false" >
<RelativeLayout
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="120dp"
android:background="#00FF00" />
</RelativeLayout>
</RelativeLayout>
Why is android:clipChildren="false" not working? I want to achieve the same effect as the CSS overflow: visible so that the child views are visible even if they're positioned outside their parent layout. I tried something like this and although the Graphical Layout in Eclipse shows the correct behaviour, on the phone it doesn't work.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#0000FF"
android:clipChildren="false"
android:clipToPadding="false" >
<RelativeLayout
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:background="#FF0000"
android:clipChildren="false"
android:clipToPadding="false" >
<RelativeLayout
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="120dp"
android:background="#00FF00" />
</RelativeLayout>
</RelativeLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我现在正在尝试类似的东西,只有当我在所有父母上使用 Booth
android:clipChildren="false"
时它才有效,下一个问题是如果在重叠的子项下有像 ListView 一样重新绘制自身的东西,然后,Android 忘记重新绘制我们的子项,它就消失了:-(唯一的方法是在每次重绘其下的视图后,在重叠的子项上手动调用 .invalidate() :-(
我还发现至少重叠子项的小和平必须在其父项中。
另一个问题是在父级之外的视图中接收触摸/单击事件。我没有找到任何解决方案。
I'm, trying something similar for now and it works only when I use booth
android:clipChildren="false"
on all parents a next problem is if under overlapped child is something that repaint itself like ListView, Android then forgot repaint our child and it disappear :-(Only way is call .invalidate() manually on overlapped child after every repaint of view under it :-(
I also found that at least small peace of overlapped child must be in the its parent.
And another problem is with receive touch/click events in view which is outside of the parent. I not found any solution for it.