FloatWindow的使用

1.在工程的 build.gradle 中添加:

allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}
2. 在应用的 build.gradle 中添加:

	dependencies {
	        compile 'com.github.yhaolpz:FloatWindow:1.0.8'
	}

3.添加权限

 

4.代码实现

package dialogdemo.zhoujian.com.floatwindowdemo;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.animation.BounceInterpolator;
import android.widget.ImageView;
import com.yhao.floatwindow.FloatWindow;
import com.yhao.floatwindow.MoveType;
import com.yhao.floatwindow.Screen;

public class MainActivity extends AppCompatActivity {
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //初始化FloatWindow
        initFloatWindow();

    }

    /**
     * 初始化FloatWindow
     */
    private void initFloatWindow() {
        ImageView imageView = new ImageView(MainActivity.this);
        imageView.setImageResource(R.drawable.icon);

        FloatWindow
                .with(getApplicationContext())
                .setView(imageView)
                .setWidth(Screen.width,0.15f)
                .setHeight(Screen.width,0.15f)
                .setX(Screen.width,0.8f)
                .setY(Screen.height,0.85f)
                .setMoveType(MoveType.inactive)
                .setMoveStyle(500,new BounceInterpolator())
                .setFilter(true,MainActivity.class)
                .setDesktopShow(true)
                .setTag("FloatWindow")
                .build();

        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(MainActivity.this,SecondActivity.class));

            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        FloatWindow.destroy("FloatWindow");
    }

    @Override
    protected void onResume() {
        super.onResume();
    }
}




你可能感兴趣的:(Android小知识点)