【问题标题】:Android ViewGroup clipping doesn't workAndroid ViewGroup 剪辑不起作用
【发布时间】:2012-01-30 02:15:51
【问题描述】:

为什么 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>

【问题讨论】:

  • 这很有趣,但我不能相反让父母夹他们的孩子。但我有线性布局。也许这就是原因?

标签: android view clipping


【解决方案1】:

我现在正在尝试类似的东西,它仅在我对所有父母使用展位 android:clipChildren="false" 时才有效,下一个问题是,如果重叠的孩子是像 ListView 一样重绘自身的东西,Android 然后忘记重绘我们的孩子,它消失:-(

唯一的方法是在重叠的子节点上手动调用 .invalidate() 在每次重绘视图之后:-( 我还发现,重叠子项的至少小平安必须在其父项中。

另一个问题是在父级之外的视图中接收触摸/点击事件。我没有找到任何解决方案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多