2016-01-20 46 views
4

我是新来的设计模式在最新的android工作室,其中包括 标签。我尝试调整文件,但最后切割工具栏。为什么android工具栏高度被切断?

第一个活动

enter image description here

first_activity.xml

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_height="match_parent" android:layout_width="match_parent" 
android:orientation="vertical"> 

    <include layout="@layout/app_bar_main" android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 

    <android.support.v4.widget.DrawerLayout 
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/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:openDrawer="start"> 

<!-- Framelayout to display Fragments --> 
<FrameLayout 
    android:id="@+id/frame_container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

<!-- Listview to display slider menu --> 
<ListView 
    android:id="@+id/main_nav_drawer" 
    android:layout_width="240dp" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:choiceMode="singleChoice" 
    android:divider="#888" 
    android:dividerHeight="1dp" 
    android:background="#fff"/> 
    <!--android:listSelector="@drawable/list_selector"--> 
     </android.support.v4.widget.DrawerLayout> </LinearLayout> 

这里是我的应用程序栏布局。

app_bar_main.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-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context=".Activities.MainActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:theme="@style/AppTheme.AppBarOverlay"> 
     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay"/> 

    </android.support.design.widget.AppBarLayout> 


</android.support.design.widget.CoordinatorLayout> 
+0

检查http://stackoverflow.com/questions/36530906/how-can-i-prevent-the-action-bar-from-被截断?answertab =最旧#tab-top –

+0

http://stackoverflow.com/questions/36530906/how-can-i-prevent-the-action-bar-from-being-cut-off?answertab=最古老的#标签顶 –

回答

6

更改工具栏的XML是这样的:

<android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:minHeight="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme.PopupOverlay"/> 

注意minHeight不允许尺寸较小,且wrap_content高度现在允许更大的工具栏。

0

尝试......

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     app:popupTheme="@style/AppTheme.PopupOverlay" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="?attr/colorPrimary" 
     android:minHeight="?attr/actionBarSize" /> 

    <android.support.v4.widget.DrawerLayout 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/drawer_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true" 
     tools:openDrawer="start"> 

     <!-- Framelayout to display Fragments --> 
     <FrameLayout 
      android:id="@+id/frame_container" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 

     <!-- Listview to display slider menu --> 
     <ListView 
      android:id="@+id/main_nav_drawer" 
      android:layout_width="240dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      android:background="#fff" 
      android:choiceMode="singleChoice" 
      android:divider="#888" 
      android:dividerHeight="1dp" /> 
     <!--android:listSelector="@drawable/list_selector"--> 
    </android.support.v4.widget.DrawerLayout> 
</LinearLayout> 
0

更改如下您app_bar_main布局 -

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 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" 
android:fitsSystemWindows="true" 
tools:context="com.bits.ketan.geocoding.MainActivity"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme.PopupOverlay" /> 


</LinearLayout> 
0

我是新来的最新的Android工作室的设计模式,在一个与 包括标签。我尝试调整文件,但结束了与切割工具栏

我有类似的问题,顺便说一句,它在真正的设备上工作。

而且,尝试使用

<include layout="@layout/app_bar_main" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 

DrawerLayout内与ToolbarAppBarLayout

检查以下几个环节:

http://developer.android.com/training/implementing-navigation/nav-drawer.html#DrawerLayout

要添加抽屉式导航器,请将您的用户界面用 DrawerLayout对象声明为您的布局的根视图。在 DrawerLayout中,添加一个视图,其中包含 屏幕(抽屉被隐藏时的主要布局)和包含抽屉导航内容的另一个 的主要内容。

而且,使用NavigationView而不是那个ListView

一个很好的例子:

http://developer.android.com/intl/es/reference/android/support/design/widget/NavigationView.html

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

    <!-- Your contents --> 

    <android.support.design.widget.NavigationView 
     android:id="@+id/navigation" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     app:menu="@menu/my_navigation_items" /> 
</android.support.v4.widget.DrawerLayout>