Android的滚动型不活动与抽屉布局滚动 [英] Android ScrollView not scrolling in Activity with Drawer Layout

查看:162
本文介绍了Android的滚动型不活动与抽屉布局滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我给你介绍我的活动:

Let me introduce you to my activity:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <include
        android:id="@+id/toolbar_actionbar"
        layout="@layout/toolbar_default"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <FrameLayout
        android:id="@+id/main_fragment_container"
        android:layout_width="match_parent"
        android:layout_below="@+id/toolbar_actionbar"
        android:layout_height="match_parent"/>

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/toolbar_actionbar">

        <FrameLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:clickable="true"
            android:layout_height="match_parent"/>

        <!-- android:layout_marginTop="?android:attr/actionBarSize"-->
        <fragment
            android:id="@+id/fragment_drawer"
            android:name="com.package.name.navigationdrawer.NavigationDrawerFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            app:layout="@layout/fragment_navigation_drawer"/>
    </android.support.v4.widget.DrawerLayout>
</RelativeLayout>

的FrameLayout main_fragment_container 是我负载随抽屉式导航选择不同的片段,但是当我加载了滚动型滚动片段不工作,我可以看到滚动条时加载的片段显示,只有一小部分是在屏幕上的时刻,但它永远不会滚动。我想,提到包住滚动型中的LinearLayout里面的一些建议,它并没有区别。

FrameLayout main_fragment_container is where I load different fragments depending on Navigation Drawer selections but when I load a fragment with a ScrollView scroll does not work, I can see the scrollbar when the fragment is loaded indicating that only a small section is on screen at the moment but it will never scroll. I tried some suggestions that mentioned encasing the ScrollView inside a LinearLayout, it made no difference.

我怀疑导航抽屉拦截,它应该达到的滚动型的事件,但我迷路了,以什么做的。这是该片段:

I suspect the navigation drawer is "intercepting" the events which should reach the ScrollView but I'm lost as to what to do. This is the fragment:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:orientation="vertical">

    <ScrollView
        android:id="@+id/fragment_who_scrollview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical"
        android:fillViewport="true">

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

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:adjustViewBounds="true"
                android:src="@drawable/header_pic_s"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="17sp"
                android:text="TEEEEEST"
                android:gravity="center"
                android:padding="20dp"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="17sp"
                android:text="TEEEEEST"
                android:gravity="center"
                android:padding="20dp"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="17sp"
                android:text="TEEEEEST"
                android:gravity="center"
                android:padding="20dp"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="17sp"
                android:text="TEEEEEST"
                android:gravity="center"
                android:padding="20dp"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="17sp"
                android:text="TEEEEEST"
                android:gravity="center"
                android:padding="20dp"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="17sp"
                android:text="TEEEEEST"
                android:gravity="center"
                android:padding="20dp"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="17sp"
                android:text="TEEEEEST"
                android:gravity="center"
                android:padding="20dp"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="17sp"
                android:text="TEEEEEST"
                android:gravity="center"
                android:padding="20dp"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="17sp"
                android:text="TEEEEEST"
                android:gravity="center"
                android:padding="20dp"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="17sp"
                android:text="TEEEEEST"
                android:gravity="center"
                android:padding="20dp"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="17sp"
                android:text="TEEEEEST"
                android:gravity="center"
                android:padding="20dp"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="17sp"
                android:text="TEEEEEST"
                android:gravity="center"
                android:padding="20dp"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="17sp"
                android:text="TEEEEEST"
                android:gravity="center"
                android:padding="20dp"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="17sp"
                android:text="TEEEEEST"
                android:gravity="center"
                android:padding="20dp"/>
        </LinearLayout>
    </ScrollView>
</LinearLayout>

感谢您的时间。

更新 - 让我添加一些额外的信息:


  • 这里的问题不是滚动型本身,而是事实,在我的活动布局DrawerLayout是'上面'的滚动型$ P ​​$ pventing任何触摸事件达到了滚动型。如果我删除DrawerLayout的滚动型卷轴就好了。

  • The problem here is not the ScrollView per se but the fact that in my activity layout the DrawerLayout is 'above' the ScrollView preventing any touch events reaching the ScrollView. If I remove the DrawerLayout the ScrollView scrolls JUST FINE.

同样的,如果我把滚动型DrawerLayout后活动布局的滚动工作好吗在滚动型,但当然如预期,因为它必须在一切之上的DrawerLayout不起作用。

Similarly if I put ScrollView after DrawerLayout in activity layout the scroll works alright in the ScrollView but of course the DrawerLayout does not work as intended since it must be on top of everything else.

我希望我正确解释自己,通过测试我敢肯定的是什么问题,但我不知道如何解决它,我的抽屉式导航的经验是有限的,我不知道如何让滚动事件传递给滚动型,而不是具有DrawerLayout拦截它。

I hope I explained myself properly, by testing I'm sure of what the problem is but I'm not sure on how to fix it, my experience with Navigation Drawer is limited and I have no idea how to let the scroll event pass to the ScrollView instead of having the DrawerLayout intercept it.

推荐答案

您应该将ID为main_fragment_container中的FrameLayout里面drawerlayout是这样的:

You should move the framelayout with id "main_fragment_container" inside drawerlayout like this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<include
    android:id="@+id/toolbar_actionbar"
    layout="@layout/toolbar_default"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />


<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"
    android:layout_below="@+id/toolbar_actionbar">

    <FrameLayout
        android:id="@+id/main_fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/toolbar_actionbar" />

    <!-- android:layout_marginTop="?android:attr/actionBarSize"-->
    <fragment
        android:id="@+id/navigation_drawer"
        android:name="vodafone.navdrawertest.NavigationDrawerFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:layout="@layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>

这篇关于Android的滚动型不活动与抽屉布局滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆