2015-11-07 3 views
-1

У меня есть фрагмент в ViewPager, который можно прокручивать вправо и влево. Но каждый имеет ScollView с TextView. Этот TextView может иметь много текста (сгенерированный кодом), поэтому я хочу, чтобы он мог прокручивать его по вертикали, но если я задействую устройство, фрагменты важнее, поэтому я могу только прокручивать его по горизонтали. Есть ли способ исправить это? мой макет:Android - прокрутка 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="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> 
+0

Что вы имеете в виду под "Фрагмент можно прокручивать вправо и влево"? Является ли «Фрагмент» внутри «ViewPager»? – PPartisan

+0

@PPartisan Да, это внутри ViewPager – Andret

+0

Возможно, что «ViewPager» перехватывает все события салфетки в этом случае. Вы можете протестировать это, создав свой собственный класс «ViewPager», переопределив 'onInterceptTouchEvent()'/'onTouchEvent()' и посмотрим, что происходит с прокруткой вверх и вниз. Я испытаю это сам, когда у меня появится такая возможность. – PPartisan

ответ

0

попробуйте этот код при запуске переписать некоторые параметры самостоятельно.

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

редактировать:

необходимо изменить высоту Scrollview. wrap_content -> match_parent и вы можете добавить это атрибуты

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> 
+0

'fragmentScrollView' означает объект класса, который расширяет фрагмент, FragmentAdapter только объекта ViewPager? И 'childScrollView' - это прокрутка, которую я хочу прокрутить? – Andret

+0

попробуйте этот код обновить – LEETAEJUN

+0

Этот код не помог, ничего не изменилось ... – Andret

Смежные вопросы