【问题标题】:Item not showing up correctly without margin没有边距的项目无法正确显示
【发布时间】:2018-03-03 17:16:06
【问题描述】:

在我的 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 这是否正常,我必须为我的徽标设置边距还是有问题?

【问题讨论】:

  • 看起来你的Drawerlayout 也覆盖了状态栏大小。添加activity和style的layout.xml。
  • @ADM 谢谢;已添加!
  • 尝试从NavigationView中删除android:fitsSystemWindows="true"
  • @ADM 通过从 android.support.v4.widget.DrawerLayout 中删除 android:fitsSystemWindows="true" 问题解决了!谢谢。
  • 哈哈。我想念判断它..Bravo。回答你自己的问题。

标签: android android-layout android-actionbar


【解决方案1】:

通过从&lt;android.support.v4.widget.DrawerLayout&gt; 中删除android:fitsSystemWindows="true" 解决了问题:

【讨论】:

    猜你喜欢
    • 2012-03-28
    • 1970-01-01
    • 2014-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-18
    • 2020-01-16
    • 1970-01-01
    相关资源
    最近更新 更多