2016-03-09 234 views
2

我剛開始在Android Studio中學習android java。Android屏幕滑動操作

而我有一個關於屏幕滑動行爲的問題。

我想創建一個屏幕幻燈片動作,讓我有我的基本佈局選項旁邊的其他選項,選擇附加選項後,我將返回到我的基本佈局。

可以代表我的想法的完美例子是Google Calculator,當用戶需要高級數學符號時,它具有綠色佈局,當用戶將右邊緣向左滑動時顯示,並且在用戶選擇一個數學符號它會回到它的基本佈局。

This is the screen shot of the calculator,photo belong to the internet

我不解釋很好,我希望你們明白我想辦法。

+1

喜歡的東西[使用ViewPager絲網幻燈片](http://developer.android.com/training/animation/screen-slide.html) ? –

+0

你想能夠在當前視圖上刷卡嗎? –

回答

3

我使用SlidingPaneLayout工作。讓我知道這個是否奏效。 enter image description here

XML

<android.support.v4.widget.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/SlidingPanel" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <RelativeLayout 
     android:id="@+id/base" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#2196F3" 
     android:orientation="vertical"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="center" 
      android:text="Hello SlidingPaneLayout!" /> 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/slider" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginLeft="20dp" 
     android:background="#F44336" 
     android:elevation="50dp"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="center" 
      android:text="Hello SlidingPaneLayout!" /> 
    </RelativeLayout> 

</android.support.v4.widget.SlidingPaneLayout> 

活動

import android.os.Bundle; 
import android.support.v4.content.ContextCompat; 
import android.support.v4.widget.SlidingPaneLayout; 
import android.support.v7.app.AppCompatActivity; 

public class MainActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     SlidingPaneLayout slidingPaneLayout = (SlidingPaneLayout) findViewById(R.id.SlidingPanel); 
     slidingPaneLayout.setSliderFadeColor(ContextCompat.getColor(this, android.R.color.transparent)); 
     slidingPaneLayout.openPane(); 
    } 
} 
+0

是的,這確實有很大幫助,感謝您在這裏提供的幫助和代碼。謝謝! – Ming

+0

沒問題。如果它解決了您的問題,請將其標記爲已解決。 –

+1

在滑出之前,如何讓滑動窗格可見?我試過了,它的行爲就像一個導航抽屜,你只能看到你是否將它滑出。我需要它像股票計算器應用程序中的部分可見。謝謝! – pez