안녕하세요.

제가 이번에 안드로이드 뉴 마켓같은 레이아웃이 들어간 앱을 개발중입니다.

간략 설명을 하자면 총 n개의 페이지가 있고 플리킹(가로)으로 페이지가 전환 되는데

안드로이드 홈 런쳐 처럼 드래그식으로 페이지 전환이 됩니다.(손가락 움직이는대로 절반 이상 넘어간 상태에서 손을때면 페이지 전환)

이런식으로 구현 하기 위해 안드로이드 풀소스의 런쳐소스를 보고

가로 페이지 전환은 구현 하였습니다. 근데 문제가 콘텐츠들이 세로 영역을 넘어가게 되면 세로스크롤도 되어

보여줘야하는데 세로 스크롤이 되지 않고 있습니다.

 

/**************************************************************************
 * @brief  : 화면 전체 플리킹을 관리하는 ViewGroup
 * @date   : 2011. 8. 31. 
 * @author : 
 * @modify : 
 **************************************************************************/
public class CopyOfCustomHorizontalScrollView extends ViewGroup
{
 private Context   m_context; // Context
 private MainTabActivity m_mainActivity;
 
 private VelocityTracker mVelocityTracker;
 
 private static final int SNAP_VELOCITY  = 1000;
 
 private float m_fDownX     = 0;
    private int mCurrentScreen = 0;
    
    private Scroller m_scroller;
 
 public CopyOfCustomHorizontalScrollView(Context context, AttributeSet attrs) 
 {
  super(context, attrs);
  this.m_context = context;
  m_scroller = new Scroller(m_context);
  m_mainActivity = new MainTabActivity();
 }
 public CopyOfCustomHorizontalScrollView(Context context, AttributeSet attrs,
   int defStyle) 
 {
  super(context, attrs, defStyle);
  this.m_context = context;
  m_scroller = new Scroller(m_context);
  m_mainActivity = new MainTabActivity();
 }
 
 @Override
 public boolean onInterceptTouchEvent(MotionEvent ev) 
 {
        return super.onTouchEvent(ev);
 }
 
 @Override
 public boolean onTouchEvent(MotionEvent event) 
 {
  int scrollX = getScrollX(); // 스크롤 x 좌료값의 위치
  
  if (mVelocityTracker == null) 
  {
             mVelocityTracker = VelocityTracker.obtain();
        }
        mVelocityTracker.addMovement(event);
        final int action = event.getAction();
        final float x = event.getX(); // Touch 이벤트가 들어온 x 좌료값의 위치
        
        switch (action) 
        {
        case MotionEvent.ACTION_DOWN:
   m_fDownX = x;
   break;
        case MotionEvent.ACTION_UP:
            final VelocityTracker velocityTracker = mVelocityTracker;
            velocityTracker.computeCurrentVelocity(1000);
            int velocityX = (int) velocityTracker.getXVelocity();
            Log.d("test", "velocityX = " + velocityX + ", SNAP_VELOCITY = " + SNAP_VELOCITY + ", mCurrentScreen = " + mCurrentScreen + ", getChildCount() = " + m_mainActivity.getChildViewCount());
            
            if (velocityX > SNAP_VELOCITY && mCurrentScreen > 0) {
                // 다음 페이지 (오른쪽)
                snapToScreen(mCurrentScreen - 1);
            } else if (velocityX < -SNAP_VELOCITY && mCurrentScreen < m_mainActivity.getChildViewCount() - 1) {
                // 이전 페이지 (왼쪽)
                snapToScreen(mCurrentScreen + 1);
            } else {
             // 제자리
                snapToDestination();
            }
            if (mVelocityTracker != null) {
                mVelocityTracker.recycle();
                mVelocityTracker = null;
            }
   break;
   
        case MotionEvent.ACTION_MOVE:
         Log.d("scroll2", "ACTION_MOVE   ==  " + scrollX);
   final int deltaX = (int) (m_fDownX - x);
   m_fDownX = event.getX();
            if (deltaX < 0) {
                if (getScrollX() > 0) {
                 scrollBy(Math.max(-scrollX, deltaX), 0);
                }
            } else if (deltaX > 0) {
                final int availableToScroll = (m_mainActivity.getDisplayWidth() * m_mainActivity.getChildViewCount()) - scrollX - m_mainActivity.getDisplayWidth();
                if (availableToScroll > 0) {
                    scrollBy(Math.min(availableToScroll, deltaX), 0);
                }
            }
            break;
        case MotionEvent.ACTION_CANCEL:
         
  }
  return true;
 }
 
 /**************************************************************************
  * @brief  : 이동할 화면을 계산.
  * @date   : 2011. 9. 1. 
  * @author : 
  * @modify : 
  **************************************************************************/
 private void snapToDestination() 
 {
        final int screenWidth = m_mainActivity.getDisplayWidth();
        final int whichScreen = (getScrollX() + (screenWidth / 2)) / screenWidth;
        snapToScreen(whichScreen);
    }
    /**************************************************************************
     * @brief  : 화면 이동
     * @date   : 2011. 9. 1. 
     * @author : 
     * @modify : 
     * @param whichScreen
     **************************************************************************/
    public void snapToScreen(int whichScreen) 
    {
        whichScreen = Math.max(0, Math.min(whichScreen, m_mainActivity.getChildViewCount() - 1));
        // 페이지가 전환 되었나 여부
        boolean changingScreens = whichScreen != mCurrentScreen;
        
        final int newX = whichScreen * m_mainActivity.getDisplayWidth();
        final int scrollX = getScrollX();
        final int delta = newX - scrollX;
        scrollTo(newX, getScrollY());
        invalidate();
        changeTabImage(whichScreen);
        mCurrentScreen = whichScreen;
    }
        
    /**************************************************************************
     * @brief  : 탭 클릭시 이동.
     * @date   : 2011. 9. 1. 
     * @author : 
     * @modify : 
     * @param position
     **************************************************************************/
    public void smoothScrollTo(int position)
    {
     scrollTo(position * m_mainActivity.m_iDisplayWidth, getScrollY());
     invalidate();
     changeTabImage(position);
     mCurrentScreen = position;
     Log.d("move", "moveToScreen2() mCurrentScreen = " + mCurrentScreen);
    }
 @Override
 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
  Log.d("test", "Workspace onLayout()");
        int childLeft = 0;
        final int count = getChildCount();
        for (int i = 0; i < count; i++) {
            final View child = getChildAt(i);
            if (child.getVisibility() != View.GONE) {
                final int childWidth = child.getMeasuredWidth();
                child.layout(childLeft, 0, childLeft + childWidth, child.getMeasuredHeight());
                childLeft += childWidth;
            }
        }
 }
 
 @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        Log.d("test", "Workspace onMeasure()");
        final int width = MeasureSpec.getSize(widthMeasureSpec);
        final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
        if (widthMode != MeasureSpec.EXACTLY) {
            throw new IllegalStateException("Workspace can only be used in EXACTLY mode.");
        }
        final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
        if (heightMode != MeasureSpec.EXACTLY) {
            throw new IllegalStateException("Workspace can only be used in EXACTLY mode.");
        }
        final int count = getChildCount();
        for (int i = 0; i < count; i++) 
        {
            getChildAt(i).measure(widthMeasureSpec, heightMeasureSpec);
        }
 }
}

 

xml 입니다

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
>
 <RelativeLayout 
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background="@drawable/top"
 >
  <ImageView 
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:background="@drawable/search"
   android:layout_centerVertical="true"
   android:layout_alignParentRight="true"
   android:layout_marginRight="5dip"
  />
 </RelativeLayout>
 <LinearLayout 
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:orientation="horizontal"
 >
  <ImageButton
   android:id="@+id/ib_tab_1"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_weight="1"
   android:background="@drawable/tab0"
   android:clickable="true"
  />
  <ImageButton 
   android:id="@+id/ib_tab_2"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_weight="1"
   android:background="@drawable/tab1"
   android:clickable="true"
  />
  <ImageButton 
   android:id="@+id/ib_tab_3"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_weight="1"
   android:background="@drawable/tab2"
   android:clickable="true"
  />
  <ImageButton 
   android:id="@+id/ib_tab_4"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_weight="1"
   android:background="@drawable/tab3"
   android:clickable="true"
  />
  <ImageButton 
   android:id="@+id/ib_tab_5"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_weight="1"
   android:background="@drawable/tab4"
   android:clickable="true"
  />
 </LinearLayout>
 
 <com.test.CopyOfCustomHorizontalScrollView 
  android:id="@+id/hoscroll"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:scrollbars="none"
  android:fadingEdge="none"
 >
   <include android:id="@+id/view1" layout="@layout/main_activity"/>
   <include android:id="@+id/view2" layout="@layout/app_main_activity"/>
   <include android:id="@+id/view3" layout="@layout/media_main_activity"/>
   <include android:id="@+id/view4" layout="@layout/special_main_activity"/>
   <include android:id="@+id/view5" layout="@layout/mybox_main_activity"/>  
     
    </com.test.CopyOfCustomHorizontalScrollView>
</LinearLayout>

도움 부탁 드립니다. 감사합니다.