Android 工具栏未正确显示
我对安卓系统的开发相当陌生,在我完成第一个应用程序之前,我必须创建的最后一个活动之一出现了问题。“我的浏览结果”类中的工具栏显示的大小不正确。 以下是我的活动\u浏览\u results.xml:Android 工具栏未正确显示,android,xml,toolbar,android-toolbar,Android,Xml,Toolbar,Android Toolbar,我对安卓系统的开发相当陌生,在我完成第一个应用程序之前,我必须创建的最后一个活动之一出现了问题。“我的浏览结果”类中的工具栏显示的大小不正确。 以下是我的活动\u浏览\u results.xml: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schem
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="@+id/activity_valid_acronym"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.redacted.CSRenA.acronymlookup.BrowseResults">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/textViewA"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="93dp"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<TextView
android:text=""
android:layout_width="700dp"
android:layout_height="wrap_content"
android:id="@+id/textViewA"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textAlignment="center"
android:textSize="30sp"
android:layout_marginTop="28dp"
android:layout_below="@+id/frameLayout2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:text=""
android:layout_width="700dp"
android:layout_height="wrap_content"
android:id="@+id/textViewB"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:textAlignment="center"
android:textSize="24sp"
android:layout_marginTop="35dp"
android:layout_below="@+id/textViewA"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageButton
android:id="@+id/share2"
android:layout_width="70dp"
android:layout_height="70dp"
android:background="@mipmap/ic_share"
android:contentDescription="Share button. Click to share this Glossary Term and Definition"
android:text="Share"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@+id/home3"
android:layout_toStartOf="@+id/home3" />
<ImageButton
android:id="@+id/home3"
android:layout_width="70dp"
android:layout_height="70dp"
android:background="@mipmap/ic_home"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:text="Button" />
<TextView
android:id="@+id/asdkjf"
android:layout_width="700dp"
android:layout_height="wrap_content"
android:layout_marginTop="29dp"
android:textAlignment="center"
android:textSize="18sp"
android:layout_below="@+id/textViewB"
android:layout_centerHorizontal="true" />
<ImageView
android:id="@+id/imageView300"
android:layout_width="160dp"
android:layout_height="80dp"
android:cropToPadding="false"
android:scaleType="centerCrop"
app:srcCompat="@mipmap/ic_logo"
android:layout_alignTop="@+id/share2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<FrameLayout
android:layout_width="0dp"
android:layout_height="134dp"
tools:layout_editor_absoluteY="8dp"
tools:layout_editor_absoluteX="8dp"
android:id="@+id/frameLayout2">
</FrameLayout>
<ImageView
android:id="@+id/imageView9000"
android:layout_width="wrap_content"
android:layout_height="500dp"
android:scaleType="fitCenter"
app:srcCompat="@drawable/eagle"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<include
layout="@layout/content_browse_results"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
以下是我的内容\u browse\u results.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.redacted.CSRenA.acronymlookup.BrowseResults"
>
</android.support.constraint.ConstraintLayout>
如果需要任何其他信息来帮助解决此问题,请告知我 这个答案真的帮助了我。为了解决这个问题,我删除了RelativeLayout中的填充。填充将工具栏向下推,因为它位于RelativeLayout内部。在这之后,唯一剩下的问题是工具栏的高度,因为它比平时短,尽管宽度问题得到了纠正。为了解决这个问题,我从AppBarLayout标签中删除了以下代码
android:layout_above="@+id/textViewA"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="93dp"
执行此操作后,工具栏将正确显示 这个答案真的帮助了我。为了解决这个问题,我删除了RelativeLayout中的填充。填充将工具栏向下推,因为它位于RelativeLayout内部。在这之后,唯一剩下的问题是工具栏的高度,因为它比平时短,尽管宽度问题得到了纠正。为了解决这个问题,我从AppBarLayout标签中删除了以下代码
android:layout_above="@+id/textViewA"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="93dp"
执行此操作后,工具栏将正确显示 只是不向根布局(RelativeLayout)添加填充,这解决了宽度问题,但条高仍然有点小,即使我将其设置为56dp。有什么想法吗?我可能错了,但看起来您的ConstraintLayout是在所有其他元素之上绘制的(RelativeLayout中的最后一个元素),因此您将看到的工具栏是content_browse_results.xml中的工具栏。对于此工具栏,您没有指定56dp的高度。如果我走错了方向,我的建议是使用LayoutInspector(AndroidStudio:Tools->Android->LayoutInspector)并验证事情是否在您预期的位置。这确实与布局有关。在我的“活动”\u“浏览”\u“结果”类中,有额外的不必要的参数处理工具栏布局。非常感谢您的帮助!你应该发表你的评论作为答案,这样我就可以相信你回答了我的问题,谢谢,但我认为你做了大部分工作:)简单地说,不要在根布局中添加填充(相对长度)。这解决了宽度问题,但条高仍然有点小,即使我将其设置为56dp。有什么想法吗?我可能错了,但看起来您的ConstraintLayout是在所有其他元素之上绘制的(RelativeLayout中的最后一个元素),因此您将看到的工具栏是content_browse_results.xml中的工具栏。对于此工具栏,您没有指定56dp的高度。如果我走错了方向,我的建议是使用LayoutInspector(AndroidStudio:Tools->Android->LayoutInspector)并验证事情是否在您预期的位置。这确实与布局有关。在我的“活动”\u“浏览”\u“结果”类中,有额外的不必要的参数处理工具栏布局。非常感谢您的帮助!你应该发表你的评论作为答案,这样我就可以相信你回答了我的问题,谢谢,但我认为你做了大部分工作:)