2016-06-08 2 views
0

여러 번 시도한 후에 내 문제를 해결하는 방법을 찾지 못했습니다. 내 레이아웃에는 appbar가있는 탐색 서랍이 있고, 그 안에는 상대적 레이아웃이있는 Cardview가 있습니다. 레이아웃 XML을 코딩하는 동안 다음 화면 내 미리보기입니다 :왜 Cardview가 Appbar에서 끝났습니까?

enter image description here

내 Cardview이 끝난 나타납니다

preview emulator

을 내가 에뮬레이터 또는 전화 응용 프로그램을 실행하면,이이 Appbar. 전체 레이아웃 코드 :

<?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:background="@android:color/darker_gray" 
android:fitsSystemWindows="true" 
android:orientation="vertical" 
android:theme="@style/AppTheme.NoActionBar" 
tools:context=".activities.display.MainActivity" 
tools:openDrawer=""> 

<android.support.v7.widget.CardView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="10dp" 
    android:layout_marginEnd="10dp" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 
    android:layout_marginStart="10dp" 
    android:layout_marginTop="70dp" 
    app:cardBackgroundColor="#80FFFFFF" 
    app:cardCornerRadius="10dp"> 

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

     <TextView 
      android:id="@+id/newresearch_title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:text="Rechercher" 
      android:textColor="#424242" 
      android:textSize="18sp" 
      android:textStyle="bold" /> 

     <EditText 
      android:id="@+id/edit1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/newresearch_title" 
      android:layout_margin="5dp" 
      android:background="@drawable/custom_edittext" 
      android:hint="Prix min" 
      android:inputType="number" 
      android:padding="5dp" 
      android:textColor="@android:color/black" /> 

     <EditText 
      android:id="@+id/edit2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/edit1" 
      android:layout_margin="5dp" 
      android:background="@drawable/custom_edittext" 
      android:hint="Prix max" 
      android:inputType="number" 
      android:padding="5dp" 
      android:textColor="@android:color/black" /> 

     <Button 
      android:id="@+id/bouton_de_recherche" 
      android:layout_width="match_parent" 
      android:layout_height="30dp" 
      android:layout_below="@+id/edit2" 
      android:layout_centerHorizontal="true" 
      android:layout_marginEnd="5dp" 
      android:layout_marginLeft="5dp" 
      android:layout_marginRight="5dp" 
      android:layout_marginStart="5dp" 
      android:layout_marginTop="25dp" 
      android:background="@drawable/custom_button" 
      android:text="Rechercher" 
      android:textColor="#424242" 
      android:textSize="12sp" /> 

    </RelativeLayout> 

</android.support.v7.widget.CardView> 

<include 
    layout="@layout/navdraw_appbar_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

<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/navdraw_header_main" 
    app:menu="@menu/activity_main_drawer" /> 

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

도움 주셔서 감사합니다.

편집 :

<?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=".activities.display.MainActivity"> 

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    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> 

<include layout="@layout/content_main" /> 

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

부모 레이아웃은 무엇입니까? –

+0

카드 뷰 –

+0

위의 앱 막대 레이아웃이 이미 완료되었으므로 작동하지 않음 :/ – Jay

답변

1

아래 navdraw_appbar의 추가 코드는이 당신을 도울 것이

<?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:background="@android:color/darker_gray" 
android:fitsSystemWindows="true" 
android:orientation="vertical" 
android:theme="@style/AppTheme.NoActionBar" 
tools:context=".activities.display.MainActivity" 
tools:openDrawer=""> 

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

<include 
    layout="@layout/navdraw_appbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 

    <RelativeLayout 
     android:id="@+id/rltv_allcontent" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
<android.support.v7.widget.CardView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="10dp" 
    android:layout_marginEnd="10dp" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 
    android:layout_marginStart="10dp" 
    android:layout_marginTop="70dp" 
    app:cardBackgroundColor="#80FFFFFF" 
    app:cardCornerRadius="10dp"> 

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

     <TextView 
      android:id="@+id/newresearch_title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:text="Rechercher" 
      android:textColor="#424242" 
      android:textSize="18sp" 
      android:textStyle="bold" /> 

     <EditText 
      android:id="@+id/edit1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/newresearch_title" 
      android:layout_margin="5dp" 
      android:background="@drawable/custom_edittext" 
      android:hint="Prix min" 
      android:inputType="number" 
      android:padding="5dp" 
      android:textColor="@android:color/black" /> 

     <EditText 
      android:id="@+id/edit2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/edit1" 
      android:layout_margin="5dp" 
      android:background="@drawable/custom_edittext" 
      android:hint="Prix max" 
      android:inputType="number" 
      android:padding="5dp" 
      android:textColor="@android:color/black" /> 

     <Button 
      android:id="@+id/bouton_de_recherche" 
      android:layout_width="match_parent" 
      android:layout_height="30dp" 
      android:layout_below="@+id/edit2" 
      android:layout_centerHorizontal="true" 
      android:layout_marginEnd="5dp" 
      android:layout_marginLeft="5dp" 
      android:layout_marginRight="5dp" 
      android:layout_marginStart="5dp" 
      android:layout_marginTop="25dp" 
      android:background="@drawable/custom_button" 
      android:text="Rechercher" 
      android:textColor="#424242" 
      android:textSize="12sp" /> 

    </RelativeLayout> 

    </android.support.v7.widget.CardView> 
</RelativeLayout> 

</LinearLayout> 
    <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/navdraw_header_main" 
    app:menu="@menu/activity_main_drawer" /> 

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

희망을 봅니다.

+0

미리보기에서 잘 보이는 것 같습니다. 작동하지 않는 것 같습니다. 문제가 있다면 화면 밖에 있습니다. 그냥 "Rechercher"라는 제목과 같은 작은 조각을보고 싶습니다. 100dp에 마진 바닥을 두어야했습니다. – Jay

+0

RelativeLayout (id rltv_allcontent 및 cardview를 사용하여) 시작 후 70dp 여백을 추가했습니다. 지금은 괜찮아요, 나는 그것을하는 가장 좋은 방법인지 정말 모르겠다. ... – Jay

+1

괜찮아. rltv_allcontent 또는 cardview에서 마진을 추가 할 수 있습니다. –

0

최근에 비슷한 문제가있었습니다. 귀하의 활동이 AppCompatActivity를 확장한다고 가정 할 때, 귀하는 귀하의 활동에 툴바를 설정 했습니까?

Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar); 
setSupportActionBar(toolbar); 
+0

도와 줘서 고마워, 그래, 이미 설정되었고 여전히 작동하지 않았다. – Jay