Android屏幕幻灯片动作

时间:2016-03-09 21:09:35

标签: android

我刚开始在Android Studio中学习android java。

我对与屏幕幻灯片操作相关的问题感到厌烦。

我想创建一个屏幕幻灯片操作,允许我在基本布局选项旁边有其他选项,在选择其他选项后,我将返回到我的基本布局。

可以代表我的想法的完美示例是Google计算器,当用户需要高级数学符号时,它具有绿色布局,当用户向右滑动右边缘时,以及用户选择之后一个数学符号,它将返回其基本布局。

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

我不太善于解释,我希望你们明白我想要解决的问题。

1 个答案:

答案 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();
    }
}