当我尝试在滚动视图中使用抽屉布局时,我的应用程序崩溃
堆栈跟踪:
<?xml version="1.0" encoding="utf-8"?>
<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:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/drawerLayout"
tools:context=".Admin.Airlines.EditAirlineActivity">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/header"/>
<TextView
android:layout_width="0dp"
android:layout_height="0dp"
android:id="@+id/internetstatus"
android:textAlignment="center" />
<android.support.v4.widget.DrawerLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="@+id/sub_drawer">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/mainContent"
android:orientation="vertical"
android:paddingTop="20dp"
android:background="@drawable/basic_background_v2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name:"
android:paddingLeft="20dp"
android:textColor="#ffffff"
android:textStyle="bold"
android:id="@+id/textView3" />
<EditText
android:id="@+id/airline_edit_name"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:paddingLeft="20dp"
android:textSize="14dp"
android:textColor="#C0C0C0"
android:textColorHint="#C0C0C0"
android:hint=" Name"
android:singleLine="true"
android:background="@drawable/textbox_border" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Arabic Name:"
android:paddingLeft="20dp"
android:textColor="#ffffff"
android:textStyle="bold"
android:id="@+id/textView4" />
<EditText
android:id="@+id/airline_edit_arabic_name"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:paddingLeft="20dp"
android:textSize="14dp"
android:textColor="#C0C0C0"
android:textColorHint="#C0C0C0"
android:hint="Arabic Name"
android:singleLine="true"
android:background="@drawable/textbox_border" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Short Name:"
android:textColor="#ffffff"
android:paddingLeft="20dp"
android:textStyle="bold"
android:id="@+id/textView5" />
<EditText
android:id="@+id/airline_edit_short_name"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:paddingLeft="20dp"
android:textSize="14dp"
android:textColor="#C0C0C0"
android:textColorHint="#C0C0C0"
android:hint="Short Name"
android:singleLine="true"
android:background="@drawable/textbox_border" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Code:"
android:paddingLeft="20dp"
android:textColor="#ffffff"
android:textStyle="bold"
android:id="@+id/textView6" />
<EditText
android:id="@+id/airline_edit_code"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:paddingLeft="20dp"
android:textSize="14dp"
android:textColor="#C0C0C0"
android:textColorHint="#C0C0C0"
android:hint="Code"
android:singleLine="true"
android:background="@drawable/textbox_border" />
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="@+id/air_line_edit_img"
android:onClick="SelectImage"
android:src="@drawable/ic_menu_camera" />
<Button
android:id="@+id/airline_edit_btn"
android:layout_width="match_parent"
android:textSize="20sp"
android:text="Save"
android:background="@drawable/red_btn"
style="@style/button_text"
android:onClick="EditAirline"
android:layout_centerHorizontal="true"
android:layout_height="wrap_content" />
</LinearLayout>
<include layout= "@layout/menu"/>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
</ScrollView>
</LinearLayout>
我使用根视图是滚动视图但是在搜索之后我发现我应该让根布局是线性布局然后 scrollview 包含抽屉布局和它的内容。我试过了,但我的应用程序仍然使用相同的堆栈跟踪崩溃。
我的XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawerLayout"
tools:context=".Admin.Airlines.EditAirlineActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/header"/>
<TextView
android:layout_width="0dp"
android:layout_height="0dp"
android:id="@+id/internetstatus"
android:textAlignment="center" />
<android.support.v4.widget.DrawerLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="@+id/sub_drawer">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/mainContent"
android:orientation="vertical"
android:paddingTop="20dp"
android:background="@drawable/basic_background_v2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name:"
android:paddingLeft="20dp"
android:textColor="#ffffff"
android:textStyle="bold"
android:id="@+id/textView3" />
<EditText
android:id="@+id/airline_edit_name"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:paddingLeft="20dp"
android:textSize="14dp"
android:textColor="#C0C0C0"
android:textColorHint="#C0C0C0"
android:hint=" Name"
android:singleLine="true"
android:background="@drawable/textbox_border" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Arabic Name:"
android:paddingLeft="20dp"
android:textColor="#ffffff"
android:textStyle="bold"
android:id="@+id/textView4" />
<EditText
android:id="@+id/airline_edit_arabic_name"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:paddingLeft="20dp"
android:textSize="14dp"
android:textColor="#C0C0C0"
android:textColorHint="#C0C0C0"
android:hint="Arabic Name"
android:singleLine="true"
android:background="@drawable/textbox_border" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Short Name:"
android:textColor="#ffffff"
android:paddingLeft="20dp"
android:textStyle="bold"
android:id="@+id/textView5" />
<EditText
android:id="@+id/airline_edit_short_name"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:paddingLeft="20dp"
android:textSize="14dp"
android:textColor="#C0C0C0"
android:textColorHint="#C0C0C0"
android:hint="Short Name"
android:singleLine="true"
android:background="@drawable/textbox_border" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Code:"
android:paddingLeft="20dp"
android:textColor="#ffffff"
android:textStyle="bold"
android:id="@+id/textView6" />
<EditText
android:id="@+id/airline_edit_code"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:paddingLeft="20dp"
android:textSize="14dp"
android:textColor="#C0C0C0"
android:textColorHint="#C0C0C0"
android:hint="Code"
android:singleLine="true"
android:background="@drawable/textbox_border" />
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="@+id/air_line_edit_img"
android:onClick="SelectImage"
android:src="@drawable/ic_menu_camera" />
<Button
android:id="@+id/airline_edit_btn"
android:layout_width="match_parent"
android:textSize="20sp"
android:text="Save"
android:background="@drawable/red_btn"
style="@style/button_text"
android:onClick="EditAirline"
android:layout_centerHorizontal="true"
android:layout_height="wrap_content" />
</LinearLayout>
<include layout= "@layout/menu"/>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
被修改
这就是我尝试但仍然存在错误
{{1}}
答案 0 :(得分:1)
你做错了布局,使DrawerLayout看到其他视图的顶视图,必须是这样的:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- here insert your scrollview and all views you need for this page this is actually your page -->
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>