android - 如何制作触摸和拖动幻灯片动画

标签 android animation

how to achive this kind of animation.

我正在尝试编写一个从互联网传输音频的音频播放器,一切进展顺利,但我想要一个像这样的动画。

已编辑

这是我的 Activity :

myActivity

我的 Activity 解释:P

Explained

我的布局 XML:

    <?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/main_content"
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                android:fitsSystemWindows="true"
                app:layout_scrollFlags="scroll|enterAlways"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

            <android.support.design.widget.TabLayout
                android:id="@+id/tabLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

        </android.support.design.widget.AppBarLayout>

        <android.support.v4.view.ViewPager
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingBottom="70dp"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

        <LinearLayout
            android:id="@+id/newactivity"
            android:layout_width="match_parent"
            android:layout_height="70dp"
            android:background="@color/md_teal_500"
            android:clickable="true"
            android:elevation="5dp"
            android:gravity="bottom|center"
            android:orientation="vertical"
            app:layout_anchor="@id/container"
            app:layout_anchorGravity="bottom|right|end">

            <SeekBar
                android:id="@+id/seekBar1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_column="0"
                android:layout_marginLeft="-20dp"
                android:layout_marginRight="-20dp"
                android:maxHeight="3dp"
                android:minHeight="3dp"
                android:padding="0dp"
                android:progressDrawable="@drawable/seekbar"
                android:thumb="@null"
                />


            <RelativeLayout
                android:layout_width="280dp"
                android:layout_gravity="start"
                android:layout_height="match_parent"
                >

                <TextView
                    android:id="@+id/title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="false"
                    android:layout_alignParentTop="false"
                    android:layout_marginLeft="15dp"
                    android:layout_marginTop="10dp"
                    android:ellipsize="marquee"
                    android:fadingEdge="horizontal"
                    android:lines="1"
                    android:marqueeRepeatLimit="marquee_forever"
                    android:maxLines="1"
                    android:scrollHorizontally="true"
                    android:text="No Marasiya Selected"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="@android:color/white"/>

                <TextView
                    android:id="@+id/album"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignLeft="@+id/title"
                    android:layout_alignStart="@+id/title"
                    android:layout_below="@+id/title"
                    android:maxLines="1"
                    android:text="Album"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="#80cbc4"/>

                <TextView
                    android:id="@+id/duration"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/title"
                    android:layout_marginLeft="10dp"
                    android:layout_toEndOf="@+id/album"
                    android:layout_toRightOf="@+id/album"
                    android:text="00:00"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="#80cbc4"/>

                <TextView
                    android:id="@+id/totalSec"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/title"
                    android:layout_toEndOf="@+id/duration"
                    android:layout_toRightOf="@+id/duration"
                    android:text=" / 00:00"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="#80cbc4"/>

            </RelativeLayout>

        </LinearLayout>

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|right"
            android:layout_marginBottom="35dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="24dp"
            android:layout_marginTop="16dp"
            android:elevation="8dp"
            android:src="@drawable/ic_play_button"
            android:tint="@color/md_brown_700"
            app:layout_anchorGravity="bottom|right|end"/>

    </android.support.design.widget.CoordinatorLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:menu="@menu/drawer_menu"/>


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

我使用 viewpager 将 fragment 添加到主要 Activity 中。底部栏添加到主 xml 布局本身

最佳答案

您可以使用 AndroidSlidingUpPanel 来完成此操作。您可以从这里获取演示代码:https://github.com/umano/AndroidSlidingUpPanel 。只需将以下依赖项添加到您的 build.gradle 文件即可使用它。

compile 'com.sothree.slidinguppanel:library:3.2.1'

之后,根据您的具体用途编辑以下 xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DemoActivity" >

<com.sothree.slidinguppanel.SlidingUpPanelLayout
    xmlns:sothree="http://schemas.android.com/apk/res-auto"
    android:id="@+id/sliding_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom"
    sothree:umanoPanelHeight="68dp"
    sothree:umanoShadowHeight="4dp"
    sothree:umanoParallaxOffset="100dp"
    sothree:umanoDragView="@+id/dragView"
    sothree:umanoOverlay="true"
    sothree:umanoScrollableView="@+id/list">

    <!-- MAIN CONTENT -->
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <android.support.v7.widget.Toolbar
            xmlns:sothree="http://schemas.android.com/apk/res-auto"
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/main_toolbar"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            sothree:theme="@style/ActionBar"
            android:layout_width="match_parent"/>
        <TextView
            android:id="@+id/main"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="?attr/actionBarSize"
            android:gravity="center"
            android:text="Main Content"
            android:clickable="true"
            android:focusable="false"
            android:focusableInTouchMode="true"
            android:textSize="16sp" />
    </FrameLayout>

    <!-- SLIDING LAYOUT -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ffffff"
        android:orientation="vertical"
        android:clickable="true"
        android:focusable="false"
        android:id="@+id/dragView">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/name"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:textSize="14sp"
                android:gravity="center_vertical"
                android:paddingLeft="10dp"/>

            <Button
                android:id="@+id/follow"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:textSize="14sp"
                android:gravity="center_vertical|right"
                android:paddingRight="10dp"
                android:paddingLeft="10dp"/>

        </LinearLayout>

    </LinearLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>

在主要内容下方添加您的 View 页面。在“滑动布局”下方添加线性布局

更新:AppCompat v23.2 在 CoordinatorLayout 中引入了 BottomSheetBehavior 行为。

通过将 BottomSheetBehavior 附加到 CoordinatorLayout 的 subview (即添加 app:layout_behavior=”android.support.design.widget.BottomSheetBehavior”),您将自动获得适当的触摸检测以在五种状态之间转换:

  • STATE_COLLAPSED:此折叠状态是默认状态,仅显示 沿底部的布局部分。高度可以控制 使用 app:behavior_peekHeight 属性(默认为 0)
  • STATE_DRAGGING:用户直接拖动时的中间状态 向上或向下拖动底部工作表
  • STATE_SETTLING: View 释放和 View 释放之间的短暂时间 进入最终位置
  • STATE_EXPANDED:底部工作表的完全展开状态,其中 整个底部工作表都是可见的(如果其高度小于 包含的 CoordinatorLayout) 或整个 CoordinatorLayout 是 已满
  • STATE_HIDDEN:默认禁用(并通过 app:behavior_hideable 属性),启用此功能允许用户滑动 向下放在底部工作表上以完全隐藏底部工作表

您可以从此处获取用于实现此功能的示例应用程序:https://github.com/NikolaDespotoski/BottomSheetSample

关于android - 如何制作触摸和拖动幻灯片动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35617644/

相关文章:

android - 我的 Android 应用程序需要 Play 商店中的 "Other"权限 - 这意味着什么以及如何修复?

Android-AnimatorSet 监听器不工作

jQuery animate() 和浏览器性能

java - 使用对象动画制作器对按钮进行动画处理

Android 模拟器从不在 Ubuntu 11 中加载

java - 如何使用Libcore.os设置环境变量

Android onSharedPreferenceChanged 在提交完成之前触发

css3 动画硬闪烁(帧之间没有淡入淡出)

jquery - 旋转分区使用离屏幻灯片动画

android - 为什么 Android Asset Studio 会剪切我的矢量图像?