用手指滑动改变活动

时间:2012-01-31 11:28:08

标签: android android-layout

我想知道如何通过手指滑动来改变活动,或者从右向左滑动手指并改变活动,就像我们在智能手机上看到图片一样。

有人知道吗?

Cumpz

4 个答案:

答案 0 :(得分:5)

答案 1 :(得分:3)

我在https://github.com/chenjishi/SlideActivity写了一个演示,你需要做的就是在项目中扩展SlidingActivity并获得幻灯片效果,这是截图: enter image description here

####旧方法

1.使活动透明

<style name="Theme.Transparent" parent="@android:style/Theme.Translucent.NoTitleBar">
    <item name="android:windowAnimationStyle">@style/activityAnimation</item>
</style>

2.使用SlidingPaneLayout

<?xml version="1.0" encoding="utf-8"?>

<android.support.v4.widget.SlidingPaneLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/slide_panel"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<View android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_gravity="left"/>
<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#E6E6E6"
        android:orientation="vertical">
</LinearLayout>

3.所以在这里你得到你想要的 enter image description here

你可以用手指滑动来移动活动,当你滑动到最右边的屏幕时你也可以摧毁它。

答案 2 :(得分:1)

使用 ViewPager 来实现您的目标。这是a tutorial

答案 3 :(得分:0)

它是Android 4.0 / 3.0中提供的“寻呼机”实现。
在早期版本中,您可以使用Android的兼容包实现它。
使用片段实现它。
您可以在SDK中找到演示项目。