在ScrollView外部绘制

时间:2015-10-14 22:45:07

标签: android

我使用的是TwoDScrollView,但为了简单起见,我们说我的布局非常简单:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rootLayout"
    android:background="@android:color/transparent"
    android:clickable="true"
    android:paddingTop="?attr/actionBarSize"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <View
    android:id="@+id/topOverview"
    android:background="#cc000000"
    android:layout_above="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

    <ScrollView
    android:id="@+id/scrollView"
    android:fillViewport="true"
    android:layout_centerVertical="true"
    android:clipChildren="false"
    android:layout_width="match_parent"
    android:layout_height="100dp">

    <ImageView
        android:adjustViewBounds="true"
        android:src="@drawable/my_photo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    </ScrollView>

    <View
    android:id="@+id/bottomOverview"
    android:background="#cc000000"
    android:layout_below="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</RelativeLayout>

所以我有一个带有ImageView的scrollView(更大的是c)。现在我想绘制外部scrollview的内容。我还想用80%的alpha-black视图覆盖这个区域(使用layout_above和layout_below),你可以在xml中看到。由于该用户将能够看到scrollview之外的区域,但外面看起来会有所不同。我尝试过clipChildren,但我没有工作。无论如何它仍然被修剪。

我在iOS上通过一行代码非常轻松地实现了这一点(加上具有正确约束的scrollView上方和下方的视图):

scrollView.clipsToBounds = false

看起来像是:

enter image description here

那么如何在Android上实现它呢?我觉得Canvas太多了。我还提出了一个想法,我可以在ScrollView外部复制ImageView,将它放在它下面并在滚动移动时移动它。但是有更简单的方法吗?

0 个答案:

没有答案