2017-02-05 10 views
-1

DrawerLayoutのヘッダーの高さは?DrawerLayoutのヘッダの高さは?

enter image description here

問題は、コンテンツがトップメニューの上に来ることです。私はコンテンツのためにパディングを追加する必要がありますandroid: layout_marginTop = "80dp"。しかし、普遍的な測定単位は何を選ぶべきですか?

drawerLayout = (DrawerLayout) findViewById(R.id.drawerMainActivity); 

XML - 構造:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drawerMainActivity" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 


    <FrameLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/containerView"> 

     <android.support.v7.widget.Toolbar 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:minHeight="?android:attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      android:id="@+id/toolBar" 
      android:fitsSystemWindows="true" 
      android:theme="@style/ThemeOverlay.AppCompat.Dark" 
      /> 
    </FrameLayout> 


    <android.support.v7.widget.RecyclerView 
     android:layout_width="240dp" 
     android:layout_height="match_parent" 
     android:id="@+id/recyclerView" 
     android:scrollbars="vertical" 
     android:background="#FFFFFF" 
     android:layout_gravity="left" 
     /> 

</android.support.v4.widget.DrawerLayout> 
+0

を重ねアンドロイドを適用します。paddingTop = "?アンドロイド:attrの/ actionBarSize" – tahsinRupam

答えて

0

使用スタイル:

<style name="CustomTheme" parent="@android:style/Theme.Light"> 
    <item name="android:windowTitleSize">30dp</item> 
</style> 

そして追加を発現させる:

<activity 
     android:name=".MainActivity" 
     android:theme="@style/CastomTheme" > 
</activity 
0

変更、このようなあなたのコード。

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drawerMainActivity" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
<Linearlayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <android.support.v7.widget.Toolbar 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:minHeight="?android:attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      android:id="@+id/toolBar" 
      android:fitsSystemWindows="true" 
      android:theme="@style/ThemeOverlay.AppCompat.Dark" 
      /> 

    <FrameLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/containerView"> 

    </FrameLayout> 
</Linearlayout> 


    <android.support.v7.widget.RecyclerView 
     android:layout_width="240dp" 
     android:layout_height="match_parent" 
     android:id="@+id/recyclerView" 
     android:scrollbars="vertical" 
     android:background="#FFFFFF" 
     android:layout_gravity="left" 
     /> 

</android.support.v4.widget.DrawerLayout> 
+0

エラー(活動を開始することができませんComponentInfo –

+0

それは、エラーの種類ですか? –

+0

私はこの解決策をお勧めします –

0

方法のLinearLayout使用1

あなたが使用することができます。

<android.support.v7.widget.Toolbar 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="?android:attr/actionBarSize" //change here 
     android:background="?attr/colorPrimary" 
     android:id="@+id/toolBar" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark" 
     /> 

は今、あなたはとパディングトップ属性を使用することができます。

android:paddingTop="?android:attr/actionBarSize" 

方法2

あなたはピクセルで、実行時にactionbar高さを見つけ、あなたのビューにパディングを設定することができますそれに応じて

// Calculate ActionBar's height 
TypedValue tv = new TypedValue(); 
if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { 
    actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,getResources().getDisplayMetrics()); 
} 

今あなたが使ってprogrametically padding Topを設定することができます。私はあなたのフラグメントコンテナあれば理解したよう

view.setPadding(0, actionBarHeight ,0,0); // 2nd param - Top 

をオーバーレイでtoolbar

このレイアウトを使用する必要があります。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/top_parent" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context=".MainActivity"> 

    <android.support.v7.widget.Toolbar 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:minHeight="?android:attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      android:id="@+id/toolBar" 
      android:fitsSystemWindows="true" 
      android:theme="@style/ThemeOverlay.AppCompat.Dark" 
      /> 

    <android.support.v4.widget.DrawerLayout 
     android:id="@+id/drawerMainActivity" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/toolbar"> 

     <FrameLayout 
      android:id="@+id/containerView" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@color/background_color" /> 

     <android.support.v7.widget.RecyclerView 
     android:layout_width="240dp" 
     android:layout_height="match_parent" 
     android:id="@+id/recyclerView" 
     android:scrollbars="vertical" 
     android:background="#FFFFFF" 
     android:layout_gravity="left" 
     /> 

    </android.support.v4.widget.DrawerLayout> 
</RelativeLayout> 

は今、uはtoolbarせずにコンテンツフレームを置き換えることができます

+0

@Almaz Vildanovは何も働いていませんでした! – rafsanahmad007

関連する問題