Android 要在图像视图上方滚动的布局

Android 要在图像视图上方滚动的布局,android,scrollview,android-linearlayout,Android,Scrollview,Android Linearlayout,我想要的布局滚动上面的图像,它的工作良好,但我需要的图像也可以点击。如何做到这一点 代码: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/LinearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android

我想要的布局滚动上面的图像,它的工作良好,但我需要的图像也可以点击。如何做到这一点

代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <FrameLayout
        android:id="@+id/frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <ImageView
            android:id="@+id/article_image"
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:layout_gravity="top"
            android:scaleType="fitXY"
            android:src="@drawable/ic_launcher" />

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                **android:paddingTop="150dp"**
                android:orientation="vertical" >

                <TextView
                    android:id="@+id/textView1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/hello_world" />

                ...so may views...
            </LinearLayout>
        </ScrollView>

    </FrameLayout>

</LinearLayout>

…所以我可以。。。

由于我添加了
android:paddingTop=“150dp”
布局在图像上方滚动,但现在如何单击图像?

首先尝试在xml文件中现有的框架布局下方添加此内容:

    <LinearLayout
    //set id here
    >
        <ImageView
                android:id="@+id/article_image"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                android:layout_gravity="top"
                android:scaleType="fitXY"
                android:src="@drawable/ic_launcher" />

            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    **android:paddingTop="150dp"**
                    android:orientation="vertical" >

                    <TextView
                        android:id="@+id/textView1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/hello_world" />

                    ...so may views...
                </LinearLayout>
            </ScrollView>
</LinearLayout>


希望这对您有所帮助。

请更新您的xml好吗?之后可以轻松单击imageview

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/LinearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <FrameLayout
            android:id="@+id/frame"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <ImageView
                android:id="@+id/article_image"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                android:layout_gravity="top"
                android:scaleType="fitXY"
                android:src="@drawable/ic_launcher" />

            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:layout_gravity="bottom">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" >

                    <TextView
                        android:id="@+id/textView1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/hello_world" />

                    ...so may views...
                </LinearLayout>
            </ScrollView>

        </FrameLayout>

    </LinearLayout>

…所以我可以。。。

尝试使用相对父视图,并在滚动视图之后添加imageview。另外,将填充顶部设置为与图像高度相同的大小

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="bottom">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:paddingTop="250dp">


                <TextView
                    android:id="@+id/textView1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Hello" />

            </LinearLayout>
        </ScrollView>

    <ImageView
        android:id="@+id/article_image"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:layout_gravity="top"
        android:scaleType="fitXY"
        android:focusable="true"
        android:clickable="true"
        android:src="@drawable/back" />

</RelativeLayout>


@PiotrGolinski在这种情况下,图像视图将位于顶部,布局将位于其下方。您是否关闭了FrameLayout?@AnshulTyagi请查看我的代码,那么您的布局应该是什么样子?@PiotrGolinski Layout可在图像上方滚动,也可单击图像我尝试了您的代码这将固定滚动视图的高度,图像视图应该是ontop,scollview应该在图像视图上方滚动并填充整个屏幕,我希望它是清晰的。@user2056563好的,我理解。这个库帮助我想我错过了在这里添加framelayout,但实际上framelayout不再需要了
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/LinearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <FrameLayout
            android:id="@+id/frame"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <ImageView
                android:id="@+id/article_image"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                android:layout_gravity="top"
                android:scaleType="fitXY"
                android:src="@drawable/ic_launcher" />

            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:layout_gravity="bottom">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" >

                    <TextView
                        android:id="@+id/textView1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/hello_world" />

                    ...so may views...
                </LinearLayout>
            </ScrollView>

        </FrameLayout>

    </LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="bottom">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:paddingTop="250dp">


                <TextView
                    android:id="@+id/textView1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Hello" />

            </LinearLayout>
        </ScrollView>

    <ImageView
        android:id="@+id/article_image"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:layout_gravity="top"
        android:scaleType="fitXY"
        android:focusable="true"
        android:clickable="true"
        android:src="@drawable/back" />

</RelativeLayout>