2013-10-25 83 views
1

我正在開發android開發。我想在主頁選項卡中製作類似的Android屏幕。在主頁選項卡上有兩個視圖。通過向左或向右拖動視圖,我可以移動視圖以顯示下一個視圖。請幫助我如何在Android中做到這一點。我需要詳細的回覆或一些教程鏈接。需要關於android佈局設計的幫助

這裏是屏幕截圖。我想做出完全相同的副本。

屏幕1

enter image description here

http://screencast.com/t/pJaLLHT74fH0

屏幕2

http://screencast.com/t/QCaOlmVJv5sJ

http://screencast.com/t/QCaOlmVJv5sJ

+0

請您提供一些更多的信息。我想幫助你,但我只看到文本屏幕1和2,沒有鏈接或圖片。如果你想得到一些幫助,我需要更多的信息 –

回答

1

單程噸o實現這將是使用ViewPager類。 Android的開發者網站上有一個很好的解釋和你將如何使用這裏ViewPager一個例子:如果不是你想要的選項卡之間刷卡

http://developer.android.com/training/animation/screen-slide.html

,他們還提供了下面這個例子:

http://developer.android.com/training/implementing-navigation/lateral.html

對於底部的圓圈指標,您可以實現Jake Wharton的ViewPagerIndicator庫。你可以下載它並在這裏找到幾個例子:http://viewpagerindicator.com/

0

我假設你已經實現了view1和view2。 所以,這裏是我的解決方案:

public class FatherLayout extends RelativeLayout implements GestureDetector.OnGestureListener, GestureDetector.OnScrollListener{ 
    private YourView view1 ; 
    private YourView view2; 

    int acitveView; // this var indicates which view is active 

    // your gesture detector here that you handle the drag events! 
    private GestureDetectorCompat mDetector; 


    public FatherLayout(Context context){ 
     super(context); 

     mDetector = new GestureDetectorCompat(this,this); 
     mDetector.setOnScrollListener(this); 
     this.addView(view2); // i assume that you want the view1 appears on the top 
     this.addView(view1); 
     activeView = 1; 
     invalidate(); 
    } 



     /*Following YOUR GESTURE DETECTOR IMPLEMENTATION HERE*/ 
    @Override 
    public boolean onTouchEvent(MotionEvent event){ 
        this.mDetector.onTouchEvent(event); 
        // Be sure to call the superclass implementation 
        return super.onTouchEvent(event); 
    } 

    @Override 
    public boolean onDown(MotionEvent event) { 
        Log.d(DEBUG_TAG,"onDown: " + event.toString()); 
        return false; 
    } 

    @Override 
    public boolean onFling(MotionEvent event1, MotionEvent event2, 
            float velocityX, float velocityY) { 
        Log.d(DEBUG_TAG, "onFling: " + event1.toString()+event2.toString()); 
        return false; 
    } 

    @Override 
    public void onLongPress(MotionEvent event) { 
        Log.d(DEBUG_TAG, "onLongPress: " + event.toString()); 
    } 

    @Override 
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, 
            float distanceY) { 
     // HERE YOU WILL DO ALL THE JOB. 
     // FOR INSTANCE IF YOU WANT TO move the view1 you will call something like this : 
     if(activeView == 1){ 

      view1.setVisible(View.VISIBLE); 
      view2.setVisible(View.INVISIBLE); 
      activeView = 0; 

     }else if(activeView == 0){ 
      view1.setVisible(View.INVISIBLE); 
      view2.setVisible(View.VISIBLE); 
      activeView = 1; 
     } 
        return false; 
    } 

    @Override 
    public void onShowPress(MotionEvent event) { 
        Log.d(DEBUG_TAG, "onShowPress: " + event.toString()); 
    } 

    @Override 
    public boolean onSingleTapUp(MotionEvent event) { 
        Log.d(DEBUG_TAG, "onSingleTapUp: " + event.toString()); 
        return false; 
    } 

    @Override 
    public boolean onDoubleTap(MotionEvent event) { 
        Log.d(DEBUG_TAG, "onDoubleTap: " + event.toString()); 
        return false; 
    } 

    @Override 
    public boolean onDoubleTapEvent(MotionEvent event) { 
        Log.d(DEBUG_TAG, "onDoubleTapEvent: " + event.toString()); 
        return false; 
    } 

    @Override 
    public boolean onSingleTapConfirmed(MotionEvent event) { 
        Log.d(DEBUG_TAG, "onSingleTapConfirmed: " + event.toString()); 
        return false; 
    } 

} 



} 
+0

謝謝你的所有幫助。現在我明白如何製作這個界面了。 –

+0

歡迎您:)請將問題標記爲已解決並投票! – karvoynistas