2017-07-26 23 views
-1

此刻只有我的GridView可滾動,但我需要我的ViewFlipper也可以滾動。我需要別人幫助ViewFlipper垂直滾動需要viewflipper也可以在此佈局中垂直滾動

這裏是我的佈局的時刻:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_grids" 
    android:layout_width="match_parent" 
    android:overScrollMode="always" 
    android:layout_height="match_parent"> 

    <ViewFlipper 
     android:layout_marginTop="56dp" 
     android:layout_width="match_parent" 
     android:layout_height="150dp" 
     android:autoStart="true" 
     android:id="@+id/vf1z" 
     android:flipInterval="3000"> 

     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:scaleType="fitXY" 
      android:background="@drawable/front" 
      android:id="@+id/imageViewz"/> 

    </ViewFlipper> 

    <GridView 
     android:numColumns="3" 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/grid" 
     android:layout_marginTop="208dp"/> 

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

</RelativeLayout> 

回答

0

您可以在ScrollView這樣的所有元素添加在你的佈局。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/activity_grids" 
android:layout_width="match_parent" 
android:overScrollMode="always" 
android:layout_height="match_parent"> 

<ScrollView 
    android:id="@+id/scrollView1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 

<ViewFlipper 
    android:layout_marginTop="56dp" 
    android:layout_width="match_parent" 
    android:layout_height="150dp" 
    android:autoStart="true" 
    android:id="@+id/vf1z" 
    android:flipInterval="3000"> 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scaleType="fitXY" 
     android:background="@drawable/front" 
     android:id="@+id/imageViewz" 
     /> 

</ViewFlipper> 

<GridView 
    android:numColumns="3" 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/grid" 
    android:layout_marginTop="208dp" 
    /> 

</ScrollView> 

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

</RelativeLayout> 

或者,如果您只想ViewFlipper是滾動的,你可以只添加ViewFlipperScrollView

0

您可以使用VerticalViewPager它的自定義實現

/** 
* Uses a combination of a PageTransformer and swapping X & Y coordinates 
* of touch events to create the illusion of a vertically scrolling ViewPager. 
* 
* Requires API 11+ 
* 
*/ 
public class VerticalViewPager extends ViewPager { 

    public VerticalViewPager(Context context) { 
     super(context); 
     init(); 
    } 

    public VerticalViewPager(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     init(); 
    } 

    private void init() { 
     // The majority of the magic happens here 
     setPageTransformer(true, new VerticalPageTransformer()); 
     // The easiest way to get rid of the overscroll drawing that happens on the left and right 
     setOverScrollMode(OVER_SCROLL_NEVER); 
    } 

    private class VerticalPageTransformer implements ViewPager.PageTransformer { 

     @Override 
     public void transformPage(View view, float position) { 

      if (position < -1) { // [-Infinity,-1) 
       // This page is way off-screen to the left. 
       view.setAlpha(0); 

      } else if (position <= 1) { // [-1,1] 
       view.setAlpha(1); 

       // Counteract the default slide transition 
       view.setTranslationX(view.getWidth() * -position); 

       //set Y position to swipe in from top 
       float yPosition = position * view.getHeight(); 
       view.setTranslationY(yPosition); 

      } else { // (1,+Infinity] 
       // This page is way off-screen to the right. 
       view.setAlpha(0); 
      } 
     } 
    } 

    /** 
    * Swaps the X and Y coordinates of your touch event. 
    */ 
    private MotionEvent swapXY(MotionEvent ev) { 
     float width = getWidth(); 
     float height = getHeight(); 

     float newX = (ev.getY()/height) * width; 
     float newY = (ev.getX()/width) * height; 

     ev.setLocation(newX, newY); 

     return ev; 
    } 

    @Override 
    public boolean onInterceptTouchEvent(MotionEvent ev){ 
     boolean intercepted = super.onInterceptTouchEvent(swapXY(ev)); 
     swapXY(ev); // return touch coordinates to original reference frame for any child views 
     return intercepted; 
    } 

    @Override 
    public boolean onTouchEvent(MotionEvent ev) { 
     return super.onTouchEvent(swapXY(ev)); 
    } 

} 

見@給以前的答案Brett

Android: Vertical ViewPager