我在android XML布局中遇到问题,我在下面的xml布局中将自定义工具栏放在顶部,但有些工具栏如何被工具栏布局下方的Linarlayout
重叠,因此我无法单击工具栏按钮,因为它位于另一个布局后面,请帮助我将其置于顶部,而不会影响XML设计的整体布局。
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/root"
android:layout_width="match_parent"
android:background="@drawable/copy"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/container_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="2"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
app:contentInsetStart="0dp"
android:layout_weight="2"
style="@style/HomeToolbar">
<ImageView
android:id="@+id/content_hamburger"
style="@style/ImageView.Hamburger"
android:layout_weight="2"
android:src="@drawable/ic_menu_90" />
</android.support.v7.widget.Toolbar>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:outlineProvider="background">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:id="@+id/sec_root">
<LinearLayout
android:id="@+id/pagerc"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:outlineProvider="background"
android:layout_weight="1" />
<com.viewpagerindicator.CirclePageIndicator
android:id="@+id/indicator"
android:padding="10dip"
android:layout_height="wrap_content"
android:layout_width="fill_parent" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="6.5">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_below="@id/pagerc"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:background="#40000000"
android:layout_height="wrap_content"
android:outlineProvider="background"
android:gravity="center_vertical|center_horizontal"
android:layout_weight="6.5">
<LinearLayout
android:id="@+id/fab_image_buttonl"
android:orientation="vertical"
android:layout_gravity="bottom|end|center_vertical|center_horizontal"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageButton
android:id="@+id/fab_image_button"
android:layout_width="@dimen/fab_button_diameter"
android:layout_height="@dimen/fab_button_diameter"
android:layout_gravity="bottom|end|center_vertical|center_horizontal"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:background="@drawable/fab_shape1"
android:src="@drawable/stadiumicon"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/fab_image_button2l"
android:orientation="vertical"
android:layout_gravity="bottom|end|center_vertical|center_horizontal"
android:layout_alignTop="@+id/fab_image_button3l"
android:layout_toLeftOf="@+id/fab_image_button3l"
android:layout_toStartOf="@+id/fab_image_button3l"
android:layout_width="@dimen/fab_button_diameter"
android:layout_height="@dimen/fab_button_diameter">
<ImageButton
android:id="@+id/fab_image_button2"
android:layout_width="@dimen/fab_button_diameter"
android:layout_height="@dimen/fab_button_diameter"
android:layout_gravity="bottom|end|center_vertical|center_horizontal"
android:background="@drawable/fab_shape1"
android:src="@drawable/resticon"
android:layout_alignTop="@+id/fab_image_button3"
android:layout_toLeftOf="@+id/fab_image_button3"
android:layout_toStartOf="@+id/fab_image_button3" />
</LinearLayout>
<LinearLayout
android:id="@+id/fab_image_button3l"
android:orientation="vertical"
android:layout_gravity="bottom|end|center_vertical|center_horizontal"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@+id/fab_image_button4l"
android:layout_toStartOf="@+id/fab_image_button4l"
android:layout_width="@dimen/fab_button_diameter"
android:layout_height="@dimen/fab_button_diameter">
<ImageButton
android:id="@+id/fab_image_button3"
android:layout_width="@dimen/fab_button_diameter"
android:layout_height="@dimen/fab_button_diameter"
android:layout_gravity="bottom|end|center_vertical|center_horizontal"
android:background="@drawable/fab_shape1"
android:src="@drawable/shopping"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@+id/fab_image_button4"
android:layout_toStartOf="@+id/fab_image_button4" />
</LinearLayout>
<LinearLayout
android:id="@+id/fab_image_button4l"
android:orientation="vertical"
android:layout_gravity="bottom|end|center_vertical|center_horizontal"
android:layout_alignParentBottom="true"
android:layout_alignTop="@+id/fab_image_buttonl"
android:layout_toLeftOf="@+id/fab_image_buttonl"
android:layout_toStartOf="@+id/fab_image_buttonl"
android:layout_width="@dimen/fab_button_diameter"
android:layout_height="@dimen/fab_button_diameter">
<ImageButton
android:id="@+id/fab_image_button4"
android:layout_width="@dimen/fab_button_diameter"
android:layout_height="@dimen/fab_button_diameter"
android:layout_gravity="bottom|end|center_vertical|center_horizontal"
android:background="@drawable/fab_shape1"
android:src="@drawable/cinema_hall"
android:layout_alignTop="@+id/fab_image_buttonl"
android:layout_toLeftOf="@+id/fab_image_buttonl"
android:layout_toStartOf="@+id/fab_image_buttonl" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</FrameLayout>
上述布局的设计看起来像这样。
非常感谢任何帮助。 感谢您的阅读!
答案 0 :(得分:1)
试试这个:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.bringToFront();
答案 1 :(得分:0)
如果你没有正确地布置它们,RelativeLayout会将它的所有子节点叠加在一起。
将包含工具栏的第一个LinearLayout设为id,例如机器人:ID =&#34; @ + ID /报头&#34;并添加android:layout_below =&#34; @ + id / header&#34;到RelativeLayout中的第二个LinearLayout。