2014-12-29 39 views
0

我在我的應用程序中實現了一個導航樣式抽屜材質設計,但只要我打開它,就會出現在所有對象下面。對象下的導航抽屜

dwr dwr2

我的代碼

layout.xml

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

    <!-- Action-bar looking view --> 
    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/actionbar_dimen" 
     android:background="@color/primary_green" 
     android:id="@+id/frameLayout"> 

     <ImageView 
      android:id="@+id/drawer_indicator" 
      android:layout_width="@dimen/actionbar_dimen" 
      android:layout_height="56dp" 
      android:scaleType="centerInside" 
      android:background="@drawable/drawer_selector" 
      android:layout_gravity="start" 
      /> 

     <TextView 
      android:id="@+id/indicator_style" 
      android:layout_width="wrap_content" 
      android:layout_height="56dp" 
      android:paddingLeft="12dp" 
      android:paddingRight="12dp" 
      android:layout_gravity="end" 
      android:text="@string/rounded" 
      android:textStyle="bold" 
      android:textColor="@color/primary_dark_green" 
      android:gravity="center" 
      android:background="@drawable/drawer_selector" 
      /> 

    </FrameLayout> 

    <!-- Content --> 
    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/actionbar_dimen" 
     android:background="@color/primary_green" 
     android:layout_below="@+id/frameLayout" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:id="@+id/frameLayout2"/> 

    <android.support.v4.widget.DrawerLayout 
     android:id="@+id/drawer_layout" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:layout_below="@+id/frameLayout2" 
     android:layout_alignParentBottom="true" 
     android:background="@color/fondo"> 

     <TextView 
      android:id="@+id/view_content" 
      android:layout_width="10dp" 
      android:layout_height="10dp" 
      android:gravity="center" 
      android:text="@string/content_hint" 
      /> 

     <TextView 
      android:id="@+id/drawer_content" 
      android:layout_width="300dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      android:gravity="center" 
      android:text="@string/drawer_hint" 
      android:textColor="@color/primary_dark_green" 
      android:background="@color/light_green" 
      /> 

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

    <RelativeLayout 
     android:layout_width="1100dp" 
     android:layout_height="fill_parent" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:layout_alignTop="@+id/frameLayout2" 
     android:background="@drawable/rounded_corner"> 

     <RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="@dimen/actionbar_dimen" 
      android:background="@color/blanco" 
      android:id="@+id/titulo_interno" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true"> 
     </RelativeLayout> 
    </RelativeLayout> 

</RelativeLayout> 

class.java

import android.os.Bundle; 
import android.support.v7.app.ActionBarActivity; 
import android.app.Activity; 
import android.content.res.Resources; 
import android.os.Bundle; 
import android.support.v4.widget.DrawerLayout; 
import android.view.View; 
import android.widget.ImageView; 
import android.widget.TextView; 

import static android.view.Gravity.START; 

public class RegistrarInciTraActivity extends ActionBarActivity 
{ 

    private DrawerArrowDrawable drawerArrowDrawable; 
    private float offset; 
    private boolean flipped; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.registrar_inci_traf_layout); 

     final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
     final ImageView imageView = (ImageView) findViewById(R.id.drawer_indicator); 
     final Resources resources = getResources(); 

     drawerArrowDrawable = new DrawerArrowDrawable(resources); 
     drawerArrowDrawable.setStrokeColor(resources.getColor(R.color.light_green)); 
     imageView.setImageDrawable(drawerArrowDrawable); 

     drawer.setDrawerListener(new DrawerLayout.SimpleDrawerListener() { 
      @Override public void onDrawerSlide(View drawerView, float slideOffset) { 
       offset = slideOffset; 

       // Sometimes slideOffset ends up so close to but not quite 1 or 0. 
       if (slideOffset >= .995) { 
        flipped = true; 
        drawerArrowDrawable.setFlip(flipped); 
       } else if (slideOffset <= .005) { 
        flipped = false; 
        drawerArrowDrawable.setFlip(flipped); 
       } 

       drawerArrowDrawable.setParameter(offset); 
      } 
     }); 

     imageView.setOnClickListener(new View.OnClickListener() { 
      @Override public void onClick(View v) { 
       if (drawer.isDrawerVisible(START)) { 
        drawer.closeDrawer(START); 
       } else { 
        drawer.openDrawer(START); 
       } 
      } 
     }); 

     final TextView styleButton = (TextView) findViewById(R.id.indicator_style); 
     styleButton.setOnClickListener(new View.OnClickListener() { 
      boolean rounded = false; 

      @Override public void onClick(View v) { 
       styleButton.setText(rounded // 
         ? resources.getString(R.string.rounded) // 
         : resources.getString(R.string.squared)); 

       rounded = !rounded; 

       drawerArrowDrawable = new DrawerArrowDrawable(resources, rounded); 
       drawerArrowDrawable.setParameter(offset); 
       drawerArrowDrawable.setFlip(flipped); 
       drawerArrowDrawable.setStrokeColor(resources.getColor(R.color.light_green)); 

       imageView.setImageDrawable(drawerArrowDrawable); 
      } 
     }); 
    } 
} 

我試着移動相對佈局,但它永遠不會工作,也許有一些方法可以總是出現在對象之上?我如何解決這個問題?

感謝

(如果你需要更多的代碼,告訴我,我編輯了這個問題)

回答

2

here

的DrawerLayout中,添加包含的主要內容一個視圖對於屏幕(隱藏抽屜時的主要佈局)以及包含導航抽屜內容的另一個視圖。

所以,你應該有:

<android.support.v4.widget.DrawerLayout> 

    <LinearLayout> 

     < /> <!-- action bar code here --> 
     <RelativeLayout /> <!-- main layout here --> 

    </LinearLayout> 

    <RelativeLayout> <!-- drawer stuff here --> 
     android:layout_gravity="start" 
    </RelativeLayout> 

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

這樣 - 我認爲 - 抽屜將覆蓋你的假動作條。爲了避免,將android:layout_marginTop="@dimen/actionbar_dimen"設置爲「抽屜東西」RelativeLayout(其高度設置爲match_parent)。無論如何,覆蓋ActionBar實際上是導航抽屜的推薦行爲,按照Material Design準則。

這意味着要告別漢堡到箭頭的動畫,我知道。

我補充說,你可能需要重新調整你的佈局(擺脫重量)的高度,也許你的代碼。但請始終指向帶有<android.support.v4.widget.DrawerLayout> ID的抽屜。

如果您使用的是Android Studio,您可以輕鬆導入「Nav Drawer」示例以查看一些工作代碼和佈局。不知道Eclipse。

+0

我試過了,是的,我在Android Studio上,但即時新的AS ..我會嘗試再次移動它。 – Aspicas

+0

@Aspicas編輯了我的答案。 – natario