在android中定制xml布局
我试图使我的搜索栏在我的标签上方,但它出现在它后面 这是我的xml文件:在android中定制xml布局,android,android-layout,uinavigationbar,Android,Android Layout,Uinavigationbar,我试图使我的搜索栏在我的标签上方,但它出现在它后面 这是我的xml文件: <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-au
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.cloud.services.drmzr.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.cloud.services.drmzr.MainActivity"
android:layout_above="@+id/topBar">
<include layout="@layout/user_search"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/topBar">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tabs"
android:background="@drawable/white_grey_border_bottom">
</android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>
</RelativeLayout>
<RelativeLayout
android:layout_below="@+id/topBar"
android:layout_above="@+id/bottomBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/container"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</android.support.v4.view.ViewPager>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="120px"
android:id="@+id/bottomBar"
android:layout_alignParentBottom="true">
<android.support.design.widget.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/bottomNavView_Bar"
android:background="@drawable/white_grey_border_top"
app:menu="@menu/bottom_navigation_menu">
</android.support.design.widget.BottomNavigationView>
</RelativeLayout>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
老实说,这不是最好的布局。测量彼此包装的所有相对布局非常昂贵。您的元素显示在彼此后面,因为您的视图是相对的,这与框架布局非常相似。我认为在你年轻的时候做这件事更好。但是如果你想让它成为相对的,就这样做吧
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
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"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/appBarLayout"
>
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tabs"
android:background="@drawable/white_grey_border_bottom">
</android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/user_search"
android:id="@+id/user_search"
android:layout_below="@+id/appBarLayout"
android:layout_height="20dp"
android:layout_width="match_parent"
/>
<android.support.v4.view.ViewPager
android:layout_below="@+id/user_search"
android:layout_above="@+id/bottomNavView_Bar"
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/container"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</android.support.v4.view.ViewPager>
<android.support.design.widget.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="120px"
android:id="@+id/bottomNavView_Bar"
android:background="@drawable/white_grey_border_top"
app:menu="@menu/bottom_navigation_menu"
android:layout_alignParentBottom="true">
</android.support.design.widget.BottomNavigationView>
</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
将搜索布局放在选项卡布局下方
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.cloud.services.drmzr.MainActivity"
android:layout_below="@id/tab_layout">
<include layout="@layout/user_search"/>
</RelativeLayout>
检查这一行:android:layout_below=“@id/tab_layout”您的@layout/user_搜索中有什么内容?
CoordinatorLayout
设置并不正确。
应该是
的直接子级。如果您想让
垂直位于
上方,可以首先将其放入
中。
和
都应该在一个
中,并且应该有app:layout\u behavior=“@string/appbar\u scrolling\u view\u behavior”
。清除所有嵌套的
s。