Search code examples
androidandroid-layoutnavigation-drawerandroid-scrollview

Layout with Scrollview and drawerlayout


i have a activity_main.xml

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >

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

<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:background="@drawable/sfondomain" />

<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="@drawable/background" >
    </ListView>

but when i run my app, it crash:

Logcat: http://paste.ubuntu.com/9699157/

MainActivity:

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final ActionBar actionBar = getActionBar();

    actionBar.hide();

}

If I remove the ScrollView, my layout work fine... I want put the ScrollView for landscape mode Thank you.. sorry for my english!


Solution

  • Try this it will work.

     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true" >
    
    <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" >
    
    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:background="@drawable/sfondomain" />
    
    <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="@drawable/background" >
        </ListView>    
    
    </LinearLayout>