2017-01-14 53 views
1

這是文件 的xml佈局在這裏,當我做出的佈局toolbar是重疊的我textView的內容,爲什麼發生這種情況。 已經嘗試了其他的東西,但沒有運氣.. !!!爲什麼我的工具欄與我的textView重疊?

<?xml version="1.0" encoding="utf-8"?> 
<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" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context="com.example.alpit.formula2.MainActivity"> 


<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:weightSum="1"> 


    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="alpit isfdfsdfwefwes great jhfjhvjhhbnmbjk" 
     android:textSize="20dp" /> 
</RelativeLayout> 

<android.support.design.widget.NavigationView 
    android:id="@+id/nav_view" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    app:menu="@menu/navigation_menu" 

    > 

</android.support.design.widget.NavigationView> 
</android.support.v4.widget.DrawerLayout> 

這是我現在的情況。 Why this is happening ?

+0

FYI:刪除'機器人:weightSum = 「1」'和設置'機器人:TEXTSIZE = 「20SP」'代替'機器人:TEXTSIZE = 「20dp」' –

+0

使用fitSystemwindow = true –

+0

完成,但仍然沒有改進。 –

回答

0

問題是僅僅因爲你有填充到您的抽屜佈局和您的相對佈局開始從頂部繪圖,其中包括paddingTop也

請嘗試下面的代碼

<?xml version="1.0" encoding="utf-8"?> 
<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" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 


    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" 
     android:weightSum="1" 
     > 


     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="alpit isfdfsdfwefwes great jhfjhvjhhbnmbjk" 
      android:textSize="20dp" /> 
    </RelativeLayout> 

    <android.support.design.widget.NavigationView 
     android:id="@+id/nav_view" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     app:menu="@menu/navigation_menu" 

     > 

    </android.support.design.widget.NavigationView> 
</android.support.v4.widget.DrawerLayout> 

也可以使用父佈局,相對佈局和使用這些抽屜裏面佈局

+0

它工作.. !!!謝謝。 –

1

添加上邊距來的RelativeLayout像

<RelativeLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_marginTop="10dp" 
android:weightSum="1"> 

我應該寫這樣的評論,但我沒有名聲,所以我增加了它的答案

+1

謝謝,它肯定有效,但不會有點hardcode.Android佈局差異手機大小可能會迷失方向。謝謝...!!! –

0

試試這個給保證金TextView的

<?xml version="1.0" encoding="utf-8"?> 
<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" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.example.alpit.formula2.MainActivity"> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="10dp" 
      android:text=" alpit isfdfsdfwefwes great jhfjhvjhhbnmbjk" 
      android:textSize="20dp" /> 
    </RelativeLayout> 
    <android.support.design.widget.NavigationView 
     android:id="@+id/nav_view" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     app:menu="@menu/navigation_menu" 
     ></android.support.design.widget.NavigationView> 
</android.support.v4.widget.DrawerLayout> 
0

不要把硬編碼值來佈置你可以試試這個,

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 


    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="@dimen/activity_vertical_margin" 
     android:text="alpit isfdfsdfwefwes great jhfjhvjhhbnmbjk" 
     android:textSize="?android:textAppearanceMedium" /> 
</RelativeLayout> 
0

刪除

android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 

並使用成relative_layout

android:layout_marginTop="@dimen/activity_vertical_margin"