2017-11-22 15 views
1

私はちょっとアンドロイド開発の新人ですが、これについて適切なやり方を見つけようとしていますが、私の中にはactivity_main.xmlというカスタムが作成されたツールバーapp_bar_parallax_fabが含まれていますnavbarをホストするactivity_mainのXML。主なアクティビティレイアウトで新しいアクティビティを開始する

私の最初の考えは、含まれているxmlを変更する方法を見つけなければならないということです。私は、私がViewFlipperを見つけたが含まれているファイルを変更する方法についてのカップル時間のために研究してきましたが、それを深く見て、viewflipperを使う正しい方法を読むのは同じアクティビティを使うときです。

私は、新しいアクティビティを宣言して、私が達成しようとしているものと類似のもののいくつかの例を投げ捨てるべきであることについて、ちょっとした助けが必要です。または、私の思考/解釈が完全に間違っていると教えてください!

下記これはactivity_main.xmlこのスニペットではかなりデフォルトです:

<?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_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:openDrawer="start"> 

     <include android:id="@+id/mainContent" layout="@layout/app_bar_parallax_fab" /> 


    <android.support.design.widget.NavigationView 
     android:id="@+id/nav_view" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:fitsSystemWindows="true" 
     app:headerLayout="@layout/nav_header_main" 
     app:menu="@menu/activity_main_drawer"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom|start" 
      android:layout_marginBottom="8dp" 
      android:layout_marginStart="15dp" 
      android:text="@string/project_owner" 
      android:textColor="@android:color/darker_gray" /> 
    </android.support.design.widget.NavigationView> 


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

私のカスタムアプリケーション/ツールバーを変更するので、私はその後、アプリバーが/どのような活動に基づいてwhitinがaccount_content.xmlを含むaccount_app_bar.xmlと呼ばれていますレイアウトが起こっている。以下は

は、カスタムツールバーのためのXMLです:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="io.tarson.cryptovision.MainActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
     android:fitsSystemWindows="true"> 
     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsing_account_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="256dp" 
      android:fitsSystemWindows="true" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed" 
      app:statusBarScrim="@android:color/transparent" 
      app:contentScrim="?attr/colorPrimary"> 
      <ImageView 
       android:id="@+id/account_profile_banner" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:fitsSystemWindows="true" 
       android:scaleType="centerCrop" 
       android:src="@drawable/cafelights" 
       app:layout_collapseMode="parallax" 
       app:layout_collapseParallaxMultiplier="0.4"/> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       app:layout_scrollFlags="scroll|enterAlways" 
       app:layout_collapseMode="pin"> 
      </android.support.v7.widget.Toolbar> 

     </android.support.design.widget.CollapsingToolbarLayout> 
     <android.support.design.widget.CollapsingToolbarLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:layout_scrollFlags="scroll|enterAlways"/> 

    </android.support.design.widget.AppBarLayout> 


    <include 
     android:id="@+id/appBarParallaxInclude" 
     layout="@layout/content_main" /> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="@dimen/fab_margin" 
     app:fabSize="normal" 
     app:layout_anchor="@id/collapsing_account_toolbar" 
     app:srcCompat="@drawable/ic_fab_edit" 
     app:layout_anchorGravity="bottom|right|end"/> 

</android.support.design.widget.CoordinatorLayout> 
+0

あなたが新しいアクティビティを開始するとはどういう意味ですか?あなたは新しい活動に移動することを意味しますか? –

+0

@YvetteColombたとえば、ダッシュボード/メインのアクティビティからアクティビティのアカウントに移動します。しかし、私は上記のように私は新しい活動を開始したいが、従来のアプリのようにnavbarを使用したいのですが、 – RTarson

+0

ナビゲーションバーがそこに残っていますか?すみません、私は混乱しています。 –

答えて

0

あなたはコメントで述べたように、あなたの主な目的は、それからアイテムを開くときに利用できる引き出しを維持することです。そのような目的のために、活動は適切ではない。その代わりに、同じアクティビティを使用して、Fragmentsで操作する必要があります。ここで

は、それが実現することができる方法の短いサンプルです:

enum MenuItems { 
    HOME, 
    SETTINGS, 
    FAQ, 
} 

private void openMenuItem(MenuItems selectedItem) { 
    Fragment instance; 
    switch (selectedItem) { 
     case HOME: 
      instance = HomeFragment.instantiate(); 
      break; 
     case SETTINGS: 
      instance = HomeFragment.instantiate(); 
      break; 
     case FAQ: 
      instance = HomeFragment.instantiate(); 
      break; 
     default: 
      throw new IllegalArgumentException(); 
    } 

    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); 
    transaction.replace(R.id.fragment_container, instance); 
    transaction.addToBackStack(null); 
    transaction.commit(); 
} 

fragment_containerは、フラグメントのための場所を保持ViewGroupタイプビュー(好ましくFrameLayout)、(通常の活動の中に全体のスペースを取る)でなければなりません。

<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_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:openDrawer="start"> 

    <android.support.design.widget.NavigationView 
     android:id="@+id/fragment_container" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:fitsSystemWindows="true" 
     app:headerLayout="@layout/nav_header_main" 
     app:menu="@menu/activity_main_drawer"> 

     <FrameLayout 
      android:id="@+id/fragment_container" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
    </android.support.design.widget.NavigationView> 


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

あなたはこれらのドキュメントを参照することができます詳細については:単純化した場合には引き出し付き全体のレイアウトは、そのような何かを見ても https://developer.android.com/training/basics/fragments/fragment-ui.html

関連する問題