2016-05-29 11 views
-1

ListViewとFragment(DrawerLayoutを含む)を含むアクティビティを1つ作った。DrawerLayout on Fragment Hide ListView

Activity.xml:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#ddffff" 
> 

<ListView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/lista" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentTop="true" /> 

<fragment 
    android:id="@+id/fragment1" 
    android:name=".Fragment" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

</RelativeLayout> 

リストビューが表示されません。私はリストビューが断片のために隠されていると思う。どうしてか分かりません。

+0

リストビューとフラグメントの両方がフルスクリーンで表示されます。フラグメントが上にあるので、リストビューをカバーします。どのようにリストビューとフラグメントを画面上に配置したいのですか? – Francesc

+0

私は、リストビューをdrawerlayoutの後ろに置いて欲しいです。このように:http://blog.teamtreehouse.com/wp-content/uploads/2015/02/nav_drawer_final.gif – tomss

答えて

0

DrawerLayoutのレイアウトを作成するには、レイアウトの一番上の要素がDrawerLayout型である必要があります。このように試してください

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <!-- The main content view --> 
    <FrameLayout 
     android:id="@+id/content_frame" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
    <!-- The navigation drawer --> 
    <ListView android:id="@+id/left_drawer" 
     android:layout_width="240dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:choiceMode="singleChoice" 
     android:divider="@android:color/transparent" 
     android:dividerHeight="0dp" 
     android:background="#111"/> 
</android.support.v4.widget.DrawerLayout> 

thisを参照してください。

0

あなたが

android:layout_width="match_parent" 
android:layout_height="match_parent" 

としてそのプロパティを設定するため、これは、フラグメントは、常に、常に全体の解像度をカバーする意味「親と一致」することを意味し、フラグメントはビュー全体をカバーしていることだけは自然です親のレイアウト(この場合は、RelativeLayoutに)、あなたは私が私の断片が、いつも私はどうなる30DPの高さを持つようにしたい場合は、たとえば、そうすることからそれを停止する数値に変更することができます。

android:layout_width="match_parent" 
android:layout_height="30dp" 

また、セカンダリレイアウトを設定するだけで設定されたサイズでフラグメントを埋めてください。

+0

エラーを返します:DrawerLayoutはMeasureSpec.EXACTLYで測定する必要があります。 – tomss

+0

DrawerLayoutを使用している場合は、Francescが述べたことに従って、すべてをラップするDrawerLayoutを作成してから、そのフラグメントを含むframeLayoutを作成してから、listview自体を作成する必要があります。 – Ilias

関連する問題