![](/img/trans.png)
[英]How to constraint a view to overlap another view in RelativeLayout
[英]Overlap sibling view with RelativeLayout
我的應用程序頂部有一個RelativeLayout。 在RelativeLayout下面,我有一個ViewPager。
為了以有意義的方式進行解釋,請假設屏幕的高度為700像素。 RelativeLayout的高度約為200像素。
我希望RelativeLayout絕對位於應用程序的頂部,以使ViewPager在它的后面。 然后,我想向ViewPager添加一個200像素的paddingTop
以使其出現在RelativeLayout下。
這是我現在擁有的布局(顯然不起作用):
<LinearLayout
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:orientation="vertical">
<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content">
...
</RelativeLayout>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
我在header
下面加載了一些數據的ListView:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
我怎樣才能做到這一點?
嘗試將linearlayout更改為framelayout。 這將允許視圖彼此重疊。
然后,將pageviewer的代碼放在相對布局上方。 這將使網頁瀏覽器在第一次呈現時顯得在相對布局的后面,而相對布局則在其頂部呈現。 Android將按照聲明的順序渲染視圖。
最后,在網頁瀏覽器中添加上邊距/內邊距,使其看起來位於相對布局下方。
您可以執行以下操作:
將ViewPager(pager)視圖移動到子RelativeLayout(標題)的頂部
<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/pager" android:paddingTop="200px" android:layout_width="match_parent" android:layout_height="match_parent" /> <RelativeLayout android:id="@+id/header" android:layout_width="match_parent" android:layout_height="wrap_content"> </RelativeLayout> </RelativeLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.