【问题标题】:Put element above element in parent RelativLayout将元素放在父 RelativLayout 中的元素之上
【发布时间】:2018-09-11 15:17:32
【问题描述】:

我想将元素TextView“singleName”放在父RelativeLayout的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>

有什么建议吗?

【问题讨论】:

  • 你需要 NestedScrollView 吗?你试过layout_abovelayout_below吗?
  • @peshkira 是的,我需要滚动视图,而 layout_above 不适用于父级 RelativeLayout

标签: java android android-layout kotlin android-relativelayout


【解决方案1】:

这个怎么样?

<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 放在屏幕底部,嵌套滚动布局应该填满屏幕上方的其余部分。

【讨论】:

    【解决方案2】:

    尝试将此添加到您的 ViewPager:

    android:layout_below="@id/singleScroll"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-10
      • 2017-12-17
      • 1970-01-01
      • 2011-01-16
      • 1970-01-01
      相关资源
      最近更新 更多