2016-12-15 44 views
0
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fillViewport="true"> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_first_time_profile" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 

    android:orientation="vertical" 
    tools:context="com.vikas.donna.ui.activities.FirstTimeProfileActivity"> 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="284dp"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/shape_rectangle_fill_gradient_primary_white"> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar_first_time_profile" 
       android:layout_width="match_parent" 
       android:layout_height="40dp" /> 


      <de.hdodenhof.circleimageview.CircleImageView 
       android:id="@+id/iv_profile_image" 
       android:layout_width="130dp" 
       android:layout_height="130dp" 
       android:layout_below="@id/toolbar_first_time_profile" 
       android:layout_centerHorizontal="true" 
       android:src="@drawable/userpic" /> 

      <com.vikas.donna.customcomponents.customfonts.CustomTextView 
       android:id="@+id/tv_profile_name" 
       style="@style/font_work_sans_medium" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/iv_profile_image" 
       android:layout_centerHorizontal="true" 
       android:text="Vikas Rohilla" 
       android:textColor="@android:color/white" 
       android:textSize="22sp" /> 

      <com.vikas.donna.customcomponents.customfonts.CustomTextView 
       android:id="@+id/tv_tag_line" 
       style="@style/font_work_sans_medium" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/tv_profile_name" 
       android:layout_centerHorizontal="true" 
       android:alpha="0.80" 
       android:text="I am software engineer" 
       android:textColor="@android:color/white" 
       android:textSize="11sp" /> 


      <com.vikas.donna.customcomponents.customfonts.CustomTextView 
       android:id="@+id/customTextView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/tv_tag_line" 
       android:layout_centerHorizontal="true" 
       android:layout_marginTop="12dp" 
       android:background="@drawable/shape_rectangle_fill_primary_trans" 
       android:drawableLeft="@drawable/red_dot" 
       android:drawablePadding="9dp" 
       android:paddingBottom="5dp" 
       android:paddingLeft="24dp" 
       android:paddingRight="24dp" 
       android:paddingTop="5dp" 
       android:text="Busy in meeting till 5.00 pm" 
       android:textColor="@android:color/white" 
       android:textSize="12sp" /> 

     </RelativeLayout> 
    </FrameLayout> 

    <android.support.design.widget.TabLayout 
     android:id="@+id/tablayout_profile" 
     android:layout_width="match_parent" 
     android:layout_height="40dp" 
     app:tabIndicatorColor="@android:color/transparent" 
     app:tabPaddingEnd="0dp" 
     app:tabPaddingStart="0dp"> 

    </android.support.design.widget.TabLayout> 


    <android.support.v4.view.ViewPager 
     android:id="@+id/view_pager_profile" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 


</LinearLayout> 

安卓:ViewPager滚动型,如果项ViewPager

超过在鉴于寻呼机片段包含一长串的话,就不会不滚动滚动。即使在添加滚动查看后,它仍显示静止画面。 如果在ViewPager子片段中添加滚动视图而不是活动,则只会滚动片段部分而不是部分。 我现在应该怎么办

+0

你不能用ViewPager和Scrollview滚动两边。它会导致性能问题,也是一种不好的做法。尝试使用嵌套的scrollview或尝试手动处理它。 –

+0

把你的viewpager放进NestedScrollView –

+0

你见过我的回答吗?你在哪里与此达成协议? –

回答

0
public class CustomScrollView extends ScrollView { 
private GestureDetector mGestureDetector; 
View.OnTouchListener mGestureListener; 

public CustomScrollView(Context context, AttributeSet attrs) { 
    super(context, attrs); 
    mGestureDetector = new GestureDetector(context, new YScrollDetector()); 
    setFadingEdgeLength(0); 
} 

@Override 
public boolean onInterceptTouchEvent(MotionEvent ev) { 
    return super.onInterceptTouchEvent(ev) 
      && mGestureDetector.onTouchEvent(ev); 
} 

// Return false if we're scrolling in the x direction 
class YScrollDetector extends SimpleOnGestureListener { 
    @Override 
    public boolean onScroll(MotionEvent e1, MotionEvent e2, 
      float distanceX, float distanceY) { 
     if (Math.abs(distanceY) > Math.abs(distanceX)) { 
      return true; 
     } 
     return false; 
    } 
} 
} 



public class NestingViewPager extends ViewPager { 

public NestingViewPager(final Context context, final AttributeSet attrs) { 
    super(context, attrs); 
} 

public NestingViewPager(final Context context) { 
    super(context); 
} 

@Override 
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) { 
    if (v != this && v instanceof ViewPager) { 
     return true; 
    } 
    return super.canScroll(v, checkV, dx, x, y); 
} 
} 
0

从什么我能看到,你已经把一个垂直ScrollView其中,在其本身,是有问题的装置内部的水平ViewPager:是一种姿态意味着滚动ViewPagerScrollViewViewPager的的Fragment进一步使问题更加复杂化:当用户触摸该列表时,焦点应位于ListView还是ScrollView

你可以尝试以下方法之一:

尝试使用RecyclerViewNestedScrollView而不是ListViewScrollView

2.可替换地,限定该interface锁着眼于ListView当它被触摸(反之亦然):

public interface FocusLock { 
    void lock(); 
    void unlock(); 
} 

然后创建自定义ListView并覆盖其dispatchTouchEvent()方法如下:

public class NestedListView extends ListView{ 

    private FocusLock mCallbackControl; 

    public void setCallback(FocusLock callbackControl) { 
     this.mCallbackControl = callbackControl; 
    } 

    .... 

    @Override 
    public boolean dispatchTouchEvent(MotionEvent event) { 

     switch (event.getAction()) { 
      case MotionEvent.ACTION_DOWN: 
      case MotionEvent.ACTION_MOVE: 
       mCallbackControl.lock(); 
       break; 

      case MotionEvent.ACTION_UP: 
      case MotionEvent.ACTION_CANCEL: 
       mCallbackControl.unlock(); 
       break; 
     } 

     return super.dispatchTouchEvent(event); 
    } 
} 

在你Fragment,你必须按如下初始化ListView

NestedListView mNestedListView = findViewById(R.id.list); 
mNestedListView.setCallback(new FocusLock() { 

       @Override 
       public void lock() { 
        mScrollView.requestDisallowInterceptTouchEvent(true); 
       } 

       @Override 
       public void unlock() { 
        mScrollView.requestDisallowInterceptTouchEvent(false); 
       } 
      }); 

希望这是有道理的。

试试这个。其中一种方法应该可行。