2017-07-18 126 views
1

我对android开发相当陌生,而且在完成我的第一个应用程序之前必须创建的最后一个活动之一出现问题。我的浏览结果类中的工具栏显示的大小不正确。 Here is how it looks.工具栏无法正常显示

这里是我的activity_browse_results.xml:

<?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> 

这里是我的content_browse_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> 

请让我知道是否需要任何其他信息,以帮助解决这个问题。

+0

简单地不添加填充到根布局(RelativeLayout) – 0X0nosugar

+0

这固定了宽度问题,但即使将它设置为56dp,但条高仍然有点小。有任何想法吗? – CSRenA

+0

我可能是错的,但它看起来像你的ConstraintLayout是在其他东西(RelativeLayout中的最后一个元素)之上绘制的,所以你会看到的工具栏是来自content_browse_results.xml的工具栏对于这个工具栏,你没有指定高度56dp。如果我在那里错误的轨道上,我的建议是使用LayoutInspector(AndroidStudio:工具 - > Android-> LayoutInspector),并验证事情是你期望他们。 – 0X0nosugar

回答

0

0X0nosugar帮我解决了这个问题。为了解决这个问题,我删除了RelativeLayout中的填充。由于它位于RelativeLayout的内部,因此填充是向下推动工具栏。在此之后,剩下的唯一问题就是工具栏的高度,因为虽然宽度问题已得到纠正,但它通常较短。为了解决这个问题,我从AppBarLayout标签中删除了以下代码。

 android:layout_above="@+id/textViewA" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_marginBottom="93dp" 

之后,工具栏显示正确。