在我的android项目中,我正在使用Theme.AppCompat.NoActionBar
并拥有一个工具栏。当我试图设置一个布局文件作为我的导航抽屉页眉时,使用任何布局框架(相对和线性布局)我应该设置一个边距值来正确显示它们并在设备屏幕的框架中显示它们!
这是我的布局文件,其中包含导航抽屉标题:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:background="@color/white"
android:layout_width="match_parent"
android:layout_height="200dp"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:src="@drawable/logo_intro"
android:layout_weight="0.5"
android:layout_gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/drawer_app_name"
android:text="@string/app_name"
android:textColor="@color/text_blue"
android:layout_gravity="center" />
</LinearLayout>
活动布局文件:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:background="@color/toolbar_background"
android:fitsSystemWindows="true"
tools:openDrawer="end"
android:id="@+id/drawer"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:background="@color/toolbar_background"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"
android:fitsSystemWindows="true"
app:menu="@menu/drawer_menu"
tools:openDrawer="end"
app:headerLayout="@layout/navigation_view"
>
</android.support.design.widget.NavigationView>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:background="@color/white"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="*.*.*.MainActivity">
<include android:id="@+id/toolbar" layout="@layout/toolbar"></include>
<RelativeLayout
android:background="@color/toolbar_background"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:src="@drawable/search_icon"
android:id="@+id/imageButton2"
android:layout_marginLeft="10dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="5dp" />
<EditText
android:layout_width="match_parent"
android:textColor="@color/white"
android:textCursorDrawable="@null"
android:layout_height="wrap_content"
android:background="@drawable/bottom_border"
android:id="@+id/editText2"
android:singleLine="true"
android:textDirection="rtl"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imageButton2"
android:layout_toEndOf="@+id/imageButton2"
android:layout_marginRight="10dp"
android:layout_marginLeft="15dp"
android:paddingBottom="10dp"
android:layout_marginBottom="20dp"
android:inputType="text"
android:textStyle="bold" />
</RelativeLayout>
<ScrollView
android:layout_width="0dp"
android:layout_height="0dp"
android:id="@+id/scrollView"
android:visibility="invisible">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/text_blue"
android:textSize="@dimen/enter_something"
android:text="Something"
android:id="@+id/textView2"
android:layout_gravity="right"
android:textStyle="bold"
android:layout_alignBottom="@+id/editText"
android:layout_alignRight="@+id/editText"
android:layout_alignEnd="@+id/editText"
android:layout_marginBottom="60dp" />
<EditText
android:layout_width="wrap_content"
android:background="@drawable/bottom_border"
android:drawableBottom="@drawable/bottom_border"
android:layout_height="@dimen/searchField_height"
android:inputType="textPersonName"
android:textCursorDrawable="@null"
android:ems="10"
android:id="@+id/editText"
android:singleLine="true"
android:textDirection="rtl"
android:paddingRight="10dp"
android:textAlignment="gravity"
android:textColor="@color/text_blue"
android:layout_marginTop="260dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:background="@drawable/button_gradiant"
android:layout_height="wrap_content"
android:text="@string/search"
android:id="@+id/button"
android:layout_below="@+id/editText"
android:layout_marginTop="44dp"
android:layout_alignRight="@+id/editText"
android:layout_alignEnd="@+id/editText"
android:layout_alignLeft="@+id/editText"
android:layout_alignStart="@+id/editText" />
</RelativeLayout>
</ScrollView>
样式文件:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="intro" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimaryDark">#569dd5</item>
</style>
here is the result that my logo is not showing correctly 这是正常的,我必须为我的徽标设置保证金或出现问题吗?
答案 0 :(得分:1)
从android:fitsSystemWindows="true"
移除<android.support.v4.widget.DrawerLayout>
: