ScrollView 不适用于添加导航抽屉
ScrollView not working with the addition of a Navigation Drawer
当我在 activity_main.xml
中添加导航抽屉标签时,此页面无法再滚动。如果我删除 activity_main.xml
中的导航抽屉更改,则滚动会正常工作。
这是我的 activity_main.xml
:
<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"
tools:context="com.example.my_app.MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:id="@+id/container2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="MergeRootFrame" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="@string/message_product"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#d66a00"
android:textSize="25sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView2"
android:layout_width="275dp"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="@string/message_tool"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ff0000"
android:textSize="35sp"
android:textStyle="bold" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_below="@+id/textView2"
android:layout_centerHorizontal="true"
android:contentDescription="@string/image1"
android:scaleType="fitCenter"
android:src="@drawable/image1" />
<TextView
android:id="@+id/textView3"
android:layout_width="256dp"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView1"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="@string/message_select"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#2F2F4F" />
</RelativeLayout>
</ScrollView>
<android.support.v4.widget.DrawerLayout
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" />
<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>
</RelativeLayout>
谁能帮帮我?我希望 ScrollView
能够再次工作。谢谢。
您的滚动视图将被抽屉布局覆盖。所以将你的滚动视图放在 Drawerlayout 中的 Framelayout 中,如下所示
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="@+id/container2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="MergeRootFrame" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="@string/message_product"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#d66a00"
android:textSize="25sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView2"
android:layout_width="275dp"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="@string/message_tool"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ff0000"
android:textSize="35sp"
android:textStyle="bold" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_below="@+id/textView2"
android:layout_centerHorizontal="true"
android:contentDescription="@string/image1"
android:scaleType="fitCenter"
android:src="@drawable/image1" />
<TextView
android:id="@+id/textView3"
android:layout_width="256dp"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView1"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="@string/message_select"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#2F2F4F" />
</RelativeLayout>
</ScrollView>
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#111"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>
当我在 activity_main.xml
中添加导航抽屉标签时,此页面无法再滚动。如果我删除 activity_main.xml
中的导航抽屉更改,则滚动会正常工作。
这是我的 activity_main.xml
:
<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"
tools:context="com.example.my_app.MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:id="@+id/container2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="MergeRootFrame" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="@string/message_product"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#d66a00"
android:textSize="25sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView2"
android:layout_width="275dp"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="@string/message_tool"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ff0000"
android:textSize="35sp"
android:textStyle="bold" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_below="@+id/textView2"
android:layout_centerHorizontal="true"
android:contentDescription="@string/image1"
android:scaleType="fitCenter"
android:src="@drawable/image1" />
<TextView
android:id="@+id/textView3"
android:layout_width="256dp"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView1"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="@string/message_select"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#2F2F4F" />
</RelativeLayout>
</ScrollView>
<android.support.v4.widget.DrawerLayout
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" />
<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>
</RelativeLayout>
谁能帮帮我?我希望 ScrollView
能够再次工作。谢谢。
您的滚动视图将被抽屉布局覆盖。所以将你的滚动视图放在 Drawerlayout 中的 Framelayout 中,如下所示
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="@+id/container2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="MergeRootFrame" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="@string/message_product"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#d66a00"
android:textSize="25sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView2"
android:layout_width="275dp"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="@string/message_tool"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ff0000"
android:textSize="35sp"
android:textStyle="bold" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_below="@+id/textView2"
android:layout_centerHorizontal="true"
android:contentDescription="@string/image1"
android:scaleType="fitCenter"
android:src="@drawable/image1" />
<TextView
android:id="@+id/textView3"
android:layout_width="256dp"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView1"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="@string/message_select"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#2F2F4F" />
</RelativeLayout>
</ScrollView>
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#111"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>