将元素放在父RelativeLayout中的元素上方

问题描述 投票:2回答:2

我想在父亲RelativeLayout上将TextView“singleName”放在ViewPager之上,是否可能?

这里是xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v4.widget.NestedScrollView
            android:id="@+id/singleScroll"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            >

            <RelativeLayout
                android:id="@+id/indicatorWrapper"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/singleName"
                    android:layout_width="wrap_content"
                    android:layout_height="@dimen/slider_height" />

            </RelativeLayout>

        </android.support.v4.widget.NestedScrollView>

        <android.support.v4.view.ViewPager
            android:id="@+id/singleSlider"
            android:layout_width="match_parent"
            android:layout_height="@dimen/slider_height"/>

    </RelativeLayout>

有什么建议吗?

java android android-layout kotlin android-relativelayout
2个回答
0
投票

尝试将此添加到您的ViewPager:

android:layout_below="@id/singleScroll"

0
投票

这个怎么样?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v4.view.ViewPager
        android:id="@+id/singleSlider"
        android:layout_width="match_parent"
        android:layout_height="@dimen/slider_height"
        android:alignParentBottom="true"
    />

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/singleScroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/singleSlider"
        >

        <RelativeLayout
            android:id="@+id/indicatorWrapper"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <TextView
                android:id="@+id/singleName"
                android:layout_width="wrap_content"
                android:layout_height="@dimen/slider_height" />

        </RelativeLayout>

    </android.support.v4.widget.NestedScrollView>

</RelativeLayout>

这应该将viewpager放在屏幕的底部,嵌套的滚动布局应该填充上面的屏幕的其余部分。

© www.soinside.com 2019 - 2024. All rights reserved.