Android-在片段中滚动滚动视图是不可能的

Android-在片段中滚动滚动视图是不可能的,android,android-fragments,scrollview,vertical-scrolling,Android,Android Fragments,Scrollview,Vertical Scrolling,我在ViewPager中有一个片段,可以左右滚动。但是每个都有ScollView和TextView。这个文本视图可以有很多文本(生成的代码),所以我希望能够垂直滚动它,但是如果我使用设备,片段更重要,所以我只能水平滑动它。有办法解决吗? 我的布局: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools

我在ViewPager中有一个片段,可以左右滚动。但是每个都有ScollView和TextView。这个文本视图可以有很多文本(生成的代码),所以我希望能够垂直滚动它,但是如果我使用设备,片段更重要,所以我只能水平滑动它。有办法解决吗? 我的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/colectionday_relative_main"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#123456"
    android:orientation="vertical"
    tools:context="${relativePackage}.${activityClass}" >

    <RelativeLayout
        android:id="@+id/colectionday_relative_top"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/rounded_layout_top" >

        <TextView
            android:id="@+id/colectionday_text_date"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginLeft="5dp"
            android:textSize="@dimen/day_date_text" />

        <ImageView
            android:id="@+id/colectionday_image_favourite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:contentDescription="@string/caution"
            android:src="@drawable/star_gray"
            android:visibility="visible" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/colecionday_relative_content"
        android:layout_width="match_parent"
        android:layout_height="fill_parent" >

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/colectionday_button_share"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="15dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="20dp"
            android:fastScrollAlwaysVisible="true"
            android:fastScrollEnabled="true" >

            <TextView
                android:id="@+id/colectionday_text_holidays"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"    
                android:fastScrollAlwaysVisible="true"
                android:fastScrollEnabled="true"
                android:gravity="center"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#FFFFFF"
                android:textSize="@dimen/day_holiday_text" />
        </ScrollView>

        <Button
            android:id="@+id/colectionday_button_share"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/colectionday_adview_bottom_dark"
            android:layout_centerHorizontal="true"
            android:text="@string/share"
            android:textColor="#FFFFFF"
            android:textSize="35sp" />

        <com.google.android.gms.ads.AdView
            android:id="@+id/colectionday_adview_bottom_dark"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            ads:adSize="BANNER"
            ads:adUnitId="ca-app-pub-1234567890/1234567890" />

        <com.google.android.gms.ads.AdView
            android:id="@+id/colectionday_adview_bottom_light"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            ads:adSize="BANNER"
            ads:adUnitId="ca-app-pub-1234567890/1234567890"
            android:visibility="invisible" />
    </RelativeLayout>

</LinearLayout>

如果运行,请尝试此代码,并为自己重写一些参数

<ScrollView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/scrollView2"
            android:scrollIndicators="right">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:paddingRight="8dp">

                <FrameLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:paddingTop="20dp"
                    android:scrollIndicators="right">


                <FrameLayout>

                </FrameLayout>

            </FrameLayout>
        </ScrollView>

编辑:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/colectionday_relative_main"
android:layout_width="match_parent"
android:layout_height="match_parent" // edit
android:focusable="true" // add
android:focusableInTouchMode="true" // add
android:descendantFocusability="beforeDescendants" // add
android:orientation="vertical"
tools:context="${relativePackage}.${activityClass}" >

// ... 

</LinearLayout>
必须修改滚动视图高度。包装内容->匹配父项 您可以添加这些属性

android:focusable="true"
android:focusableInTouchMode="true"
android:descendantFocusability="beforeDescendants"
edit2:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/colectionday_relative_main"
android:layout_width="match_parent"
android:layout_height="match_parent" // edit
android:focusable="true" // add
android:focusableInTouchMode="true" // add
android:descendantFocusability="beforeDescendants" // add
android:orientation="vertical"
tools:context="${relativePackage}.${activityClass}" >

// ... 

</LinearLayout>

// ... 

您所说的“片段可以左右滚动”是什么意思?
片段是否在
ViewPager
内?@PPartisan是的,它在ViewPagerIt内。在这种情况下,
ViewPager
可能正在拦截所有刷卡事件。您可以通过创建自己的
ViewPager
类来测试这一点,覆盖
onInterceptTouchEvent()
/
onTouchEvent()
,并查看上下滑动会发生什么。如果有机会,我会自己测试。@PPartisan它不是thuth,在另一个地方,我有包含片段的viewpager,每个都包含gridview,可以简单地垂直滚动,也可以水平滚动。问题没有发生它发生在所有设备和SDK中?如何包装片段本身?
fragmentScrollView
表示扩展片段的类的对象,只是ViewPager对象的FragmentAdapter?和
childScrollView
这是我要滚动的滚动视图吗?布局的根元素是LinearLayout-再次-没有任何更改。什么是“android:layout_over=“@+id/colectionday_按钮_share”?显示所有布局代码我添加了它,请查找。