介绍一个名为Dragger的android控件

前言

最近在做一个项目的时候要求使用一个弹出的效果,正好遇见如下的一个效果,



感觉效果很好看就用了

项目地址如下:Dragger

开始使用:(开发环境为Android Studio)

  1. 在你的build.gradle文件中添加如下内容
repositories {
  maven {
    url "https://jitpack.io"
  }
}
dependencies {
  compile 'com.github.ppamorim:dragger:1.2'
}
  1. 新建一个Main2Activity
    activity_main2.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:padding="16dp"
        android:src="@mipmap/dragger"
        android:background="@color/gray"/>

</FrameLayout>

Main2Activity.java

public class Main2Activity extends DraggerActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        DraggerView draggerView = (DraggerView) findViewById(R.id.dragger_view);
        draggerView.setDraggerPosition(DraggerPosition.BOTTOM);
    }
}
  1. 修改MainActivity.java
    在activity_main.xml中添加一个button后在MainActivity.java里面添加如下代码
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button btn = (Button) findViewById(R.id.btn);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, Main2Activity.class);
                startActivity(intent);
            }
        });
    }

解释

新建的Main2Activity其实就是那个效果中弹出的Activity,通过MainActivity中的按钮跳转到Main2Activity后执行
draggerView的setDraggerPosition的方法,其中参数为DraggerPosition.BOTTOM表示的是向下弹出,其他几种详见官方的例子

一些其他可以使用的方法

setDraggerCallback(DraggerCallback) //Interface that's provides some infos of the animation.
setSlideEnabled(boolean) //Enable or disable the drag, useful to use with ScrollViews.
setHorizontalDragRange(float) //Draggable distance that the draggableView can use, horizontally.
setVerticalDragRange(float) //Draggable distance that the draggableView can use, vertically.
setRunAnimationOnFinishInflate(boolean) //Run the initial animation, useful if you only want the drag function.
setDraggerLimit(float) //Set the max limit drag, default is 0.5 (center of the screen).
setDraggerPosition(DraggerPosition) //Set the position of archor.
setTension(float) //Tension of the animation. This represent with the friction, how much time the animation will be executed.
setFriction(float) //Friction of the animation. This represent with the tension, how much friction is applied at the tension animation.
show() //Show the drag view with Rebound animation.
closeActivity() //Simply close the activity with Rebound animation, based of the DraggerPosition choosen.
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,455评论 25 708
  • 1.什么是Activity?问的不太多,说点有深度的 四大组件之一,一般的,一个用户交互界面对应一个activit...
    JoonyLee阅读 5,763评论 2 51
  • ¥开启¥ 【iAPP实现进入界面执行逐一显】 〖2017-08-25 15:22:14〗 《//首先开一个线程,因...
    小菜c阅读 6,537评论 0 17
  • 一直说自己喜欢英语,但也没比别人付出多少努力,特别是看到别人为学习英语的努力付出,真觉得自己大言不惭。
    Sara_馨阅读 210评论 0 0
  • 曾经我只想要你一句对不起 如今我只想说声原谅你 只因命运的多舛 我怕来不及诉说 你也来不及听见 趁着这日落的黄昏 ...
    淡雅月色阅读 285评论 8 6