您的位置:首页 > 移动开发 > Android开发

介绍一个名为dragger的android控件

2017-10-16 21:52 411 查看

前言

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



感觉效果很好看就用了

项目地址如下:Dragger

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

在你的build.gradle文件中添加如下内容

repositories {
maven {
url "https://jitpack.io"
}
}


dependencies {
compile 'com.github.ppamorim:dragger:1.2'
}


新建一个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);
}
}


修改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 控件