这可能是与我办理的布局方式有问题。排序对Java和Android SDK。我使用Android的工作室。
我在这一点上的目标是有一个应用程序将一个具有显示有OFF按钮和保存按钮,在顶部的一个图标底部的导航栏和工具栏的屏幕。工具栏和导航栏之间应该是一个空白,白色屏幕。
但我遇到了麻烦工具栏仅停留在屏幕的顶部。灰色的背景占据整个屏幕的什么是白色背景前。 这里的截图。
和这里是我有:
<的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android的xmlns:工具=http://schemas.android.com/tools机器人:layout_width =match_parent机器人:layout_height =match_parent工具:上下文=ContactActivity。>< RelativeLayout的 机器人:ID =@ + ID /工具栏 机器人:layout_width =FILL_PARENT 机器人:layout_height =WRAP_CONTENT 机器人:layout_alignParentLeft =真 机器人:layout_alignParentTop =真 机器人:背景=@色/ toolbar_background> <切换按钮 机器人:ID =@ + ID / toggleButtonEdit 机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT 机器人:layout_alignParentleft =真 机器人:layout_marginLeft =20dp 机器人:文字=@字符串/ toggle_button/> <按钮 机器人:ID =@ + ID / buttonSave 机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT 机器人:layout_alignParentRight =真 机器人:layout_marginRight =20dp 机器人:文本=保存/> < RelativeLayout的 机器人:ID =@ + ID /导航栏 机器人:layout_width =FILL_PARENT 机器人:layout_height =WRAP_CONTENT 机器人:layout_alignParentBottom =真 机器人:layout_centerHorizontal =真 机器人:背景=@彩色/ navbar_background 机器人:重力=CENTER_HORIZONTAL> <的ImageButton 机器人:ID =@ + ID / imageButtonList 机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT 机器人:layout_centerVertical =真 机器人:layout_marginRight =20dp 机器人:contentDescription =联系人列表按钮 机器人:SRC =@绘制/ contactlisticon/> <的ImageButton 机器人:ID =@ + ID / imageButtonMap 机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT 机器人:layout_toRight0f =@ ID / imageButtonList 机器人:contentDescription =跟地图按钮 机器人:SRC =@绘制/ mapicon/> <的ImageButton 机器人:ID =@ + ID / imageButtonSettings 机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT 机器人:layout_marginLeft =20dp 机器人:contentDescription =设置按钮 机器人:layout_toRight0f =@ ID / imageButtonMap 机器人:SRC =绘制/ settingsicon/> < / RelativeLayout的>
解决方案
您是那种缺少工具栏
的地步。在读到它工具栏preVIEW 。您在另一端使用 RelativeLayout的
为工具栏
这是一种浪费。
有一个底部的工具栏,你可以使用另一种工具栏中的独立(如链接描述),或者使用的LinearLayout
是这样的:
<的LinearLayout 机器人:ID =@ + ID / check_in_bottom_toolbar 机器人:layout_width =match_parent 机器人:layout_height =WRAP_CONTENT 机器人:layout_alignParentBottom =真正的> ...< / LinearLayout中>
这是假设你的根布局是一种 RelativeLayout的
This could be a problem with the way I'm handling layouts. Sort of new to Java and Android SDK. I'm using Android Studio.
My goal at this point is to have an app going which has the screen showing a navigation bar at the bottom with an icon, and a toolbar at the top with an "OFF" button and a "Save" button. Between the toolbar and the navigation bar should be a blank, white screen.
But I'm having trouble getting the toolbar to just stay at the top of the screen. The grey background takes up the entire screen in front of what was the white background. Here's a screenshot.
And here's what I have:
<RelativeLayout 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"
tools:context=".ContactActivity">
<RelativeLayout
android:id="@+id/toolbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@color/toolbar_background">
<ToggleButton
android:id="@+id/toggleButtonEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentleft="true"
android:layout_marginLeft="20dp"
android:text="@string/toggle_button" />
<Button
android:id="@+id/buttonSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"
android:text="Save" />
<RelativeLayout
android:id="@+id/navbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@color/navbar_background"
android:gravity="center_horizontal">
<ImageButton
android:id="@+id/imageButtonList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="20dp"
android:contentDescription="Contact List Button"
android:src="@drawable/contactlisticon" />
<ImageButton
android:id="@+id/imageButtonMap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRight0f="@id/imageButtonList"
android:contentDescription="Contact Map Button"
android:src="@drawable/mapicon" />
<ImageButton
android:id="@+id/imageButtonSettings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:contentDescription="Settings Button"
android:layout_toRight0f="@id/imageButtonMap"
android:src="drawable/settingsicon" />
</RelativeLayout>
解决方案
You are kind of missing the point of a Toolbar
. read about it at Toolbar preview. You on the other end are using RelativeLayout
as a Toolbar
which is wasteful.
to have a Bottom toolbar you can use another standalone toolbar (as described in the link) or use a LinearLayout
like this:
<LinearLayout
android:id="@+id/check_in_bottom_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
...
</LinearLayout>
This is assuming that your root Layout is a RelativeLayout