2016-06-24 2 views
1

먼저 툴바를 설치 한 다음 리사이클 러 뷰를 추가했지만 툴바가 사라졌습니다. 나는 도구 모음을 표시하기 위해 모든 것을 시도했지만 항상 실패했습니다. 어떻게 도구 모음을 다시 가져올 수 있는지 말해 줄 수 있습니까? 미리 감사드립니다. 여기 Android에서 툴바가 표시되지 않습니다.

public class MainActivity extends AppCompatActivity implements FragmentDrawer.FragmentDrawerListener{ 

    private Toolbar mToolbar; 
    private FragmentDrawer drawerFragment; 

    private RecyclerView recyclerView; 
    private IsAdapter isAdapter; 
    private List<Is> isList; 


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

     mToolbar = (Toolbar) findViewById(R.id.toolbar); 

     setSupportActionBar(mToolbar); 
     getSupportActionBar().setDisplayShowHomeEnabled(true); 

     recyclerView = (RecyclerView) findViewById(R.id.recycler_view); 

     isList = new ArrayList<>(); 
     isAdapter = new IsAdapter(this, isList); 


     RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(this, 1); 
     recyclerView.setLayoutManager(mLayoutManager); 
     recyclerView.addItemDecoration(new GridSpacingItemDecoration(1, dpToPx(10), true)); 
     recyclerView.setItemAnimator(new DefaultItemAnimator()); 
     recyclerView.setAdapter(isAdapter); 

     prepareIsler(); 

     drawerFragment = (FragmentDrawer) 
       getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer); 
     drawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), mToolbar); 
     drawerFragment.setDrawerListener(this); 



     getSupportActionBar().setTitle("TTT"); 
     // display the first navigation drawer view on app launch 
     displayView(0); 


    } 

레이아웃 코드 : 여기 내 자바 코드

<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"> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <LinearLayout 
      android:id="@+id/container_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

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

     <!-- <include 
       android:id="@+id/toolbar" 
       layout="@layout/toolbar" /> --> 
     </LinearLayout> 

     <FrameLayout 
      android:id="@+id/container_body" 
      android:layout_width="fill_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" /> 
    </LinearLayout> 

    <fragment 
     android:id="@+id/fragment_navigation_drawer" 
     android:name="com.example.neozeka1.dts2.FragmentDrawer" 
     android:layout_width="@dimen/nav_drawer_width" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     app:layout="@layout/fragment_navigation_drawer" 
     tools:layout="@layout/fragment_navigation_drawer" /> 

    <RelativeLayout 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:background="@color/white" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     tools:context="info.androidhive.cardview.MainActivity" 
     tools:showIn="@layout/activity_main"> 

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/recycler_view" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:clipToPadding="false" 
      android:scrollbars="vertical" /> 

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

'DrawerLayout'에서 하나의 내용'보기 '만 있으면됩니다. 따라서 서재가 아닌 모든 것은 서랍 ''의'ViewGroup '에 있어야합니다. –

+0

@MikeM 예를 보여 주시겠습니까? 고마워요. – jason

+1

사실, 당신이하려는 일을 말할 수 없기 때문입니다. 'RecyclerView'가 주 콘텐츠 인 경우,'container_toolbar' 아래의 가장 바깥 쪽'LinearLayout' 내부로 옮기고'RelativeLayout'과'FrameLayout'을 제거하십시오. 'container_toolbar''''LinearLayout'도 그 안에 들어갈 것이 없다면 빼낼 수 있습니다. –

답변

1

이 계층 구조를 만듭니다.

<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"> 

<!-- Main Layout --> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:id="@+id/container_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <include 
      android:id="@+id/toolbar" 
      layout="@layout/toolbar" /> 
    </LinearLayout> 

    <FrameLayout 
     android:id="@+id/container_body" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" /> 
</LinearLayout> 

<!-- Left Drawer --> 
<fragment 
    android:id="@+id/fragment_navigation_drawer" 
    android:layout_width="@dimen/nav_drawer_width" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    app:layout="@layout/fragment_navigation_drawer" 
    android:name="com.findthewayapp.fragments.NavigationDrawerFragment" 
    tools:layout="@layout/fragment_navigation_drawer" /> 
</android.support.v4.widget.DrawerLayout> 
+0

'RecyclerView'는 어디에 있습니까? – jason

+0

@jason 'RecycleView' 계층 구조를 제공하고 있으며 다른 모든 것들은'FrameLayout'에 있거나'RelativeLayout'을 사용할 수 있습니다. Mike M.이 'Pattern'을 주석으로 남겨 두었습니다. – Ironman

+0

그래서'FrameLayout' 안에 RecycleView를 추가해야합니까? – jason

2

은이 같은 AppBar에서 도구 모음 위젯을 넣어 -

<android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/appbar" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 

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

을 그리고 - 안드로이드 : below = "@ + id/귀하의 recyclerview에있는 appbar"

<android.support.v7.widget.RecyclerView 
     android:id="@+id/my_recycler_view" 
     android:scrollbars="vertical" 
     android:layout_below="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 

희망이 있으면 도움이 될 것입니다.

+0

루트에서'RelativeLayout'을 사용해야합니까? 감사. – jason

+0

예 ... 괜찮습니다. –

관련 문제