- Support three modes:
OverlaySystem
、OverlayActivity
andOverlayViewGroup
OverlaySystem
: Display FloatingView above other appsOverlayActivity
: Display FloatingView above certain ActivityOverlayViewGroup
: Display FloatingView above certain ViewGroup- Move FloatingView with finger
- Scale FloatingView with two fingers (can be disabled)
- Listen to click and double-click events
- Define 9 initial position for FloatingView
- Define initial paddings for FloatingView
- Hold FloatingView object, so that you can change the content of FloatingView dynamically, and set OnClickListener for each child view of FloatingView
Add it in your build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
Add the dependency in the form:
dependencies {
compile 'com.github.hzw1199:FloatingView:1.6.0'
}
Configure and display
OverlaySystem
mode
onCreate:
FloatingViewConfig config = new FloatingViewConfig.Builder()
.setPaddingLeft(paddingLeft)
.setPaddingTop(paddingTop)
.setPaddingRight(paddingRight)
.setPaddingBottom(paddingBottom)
.setGravity(gravity)
.build();
floatingView = new FloatingView(OverlaySystemActivity.this, R.layout.view_floating, config);
floatingView.showOverlaySystem();
onDestroy:
if (floatingView != null) {
floatingView.hide();
}
OverlayActivity
mode
onAttachedToWindow:
FloatingViewConfig config = new FloatingViewConfig.Builder()
.setPaddingLeft(paddingLeft)
.setPaddingTop(paddingTop)
.setPaddingRight(paddingRight)
.setPaddingBottom(paddingBottom)
.setGravity(gravity)
.build();
floatingView = new FloatingView(OverlaySystemActivity.this, R.layout.view_floating, config);
floatingView.showOverlayActivity();
onDetachedFromWindow:
if (floatingView != null) {
floatingView.hide();
}
OverlayViewGroup
mode
onCreate:
lyViewGroup.post(new Runnable() {
@Override
public void run() {
FloatingViewConfig config = new FloatingViewConfig.Builder()
.setPaddingLeft(paddingLeft)
.setPaddingTop(paddingTop)
.setPaddingRight(paddingRight)
.setPaddingBottom(paddingBottom)
.setGravity(gravity)
.setDisplayWidth(lyViewGroup.getWidth())
.setDisplayHeight(lyViewGroup.getHeight())
.build();
floatingView = new FloatingView(OverlaySystemActivity.this, R.layout.view_floating, config);
floatingView.showOverlayViewGroup(lyViewGroup);
}
});
onDestroy:
if (floatingView != null) {
floatingView.hide();
}
lyViewGroup
is the ViewGroup to display FloatingView above
Click event
floatingView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
Double-click event
floatingView.setOnDoubleClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
Maximize zoom
floatingView.full();
LayoutInflater mInflater = LayoutInflater.from(AdvancedControlActivity.this);
View floatingView = mInflater.inflate(R.layout.view_advanced_control, null, false);
floatingView = new FloatingView(AdvancedControlActivity.this, floatingView, config);
LayoutInflater mInflater = LayoutInflater.from(AdvancedControlActivity.this);
View floatingView = mInflater.inflate(R.layout.view_advanced_control, null, false);
floatingView = new FloatingView(AdvancedControlActivity.this, floatingView, config);
final View vTop = floatingView.findViewById(R.id.v_top);
final View vMiddle = floatingView.findViewById(R.id.v_middle);
final View vBottom = floatingView.findViewById(R.id.v_bottom);
final TextView tvTime = floatingView.findViewById(R.id.tv_time);
View.OnClickListener onClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
if (v == vTop) {
Toast.makeText(AdvancedControlActivity.this, "Top clicked", Toast.LENGTH_SHORT).show();
} else if (v == vMiddle) {
Toast.makeText(AdvancedControlActivity.this, "Middle clicked", Toast.LENGTH_SHORT).show();
} else if (v == vBottom) {
Toast.makeText(AdvancedControlActivity.this, "Bottom clicked", Toast.LENGTH_SHORT).show();
}
tvTime.setText(String.valueOf(System.currentTimeMillis()));
}
};
vTop.setOnClickListener(onClickListener);
vMiddle.setOnClickListener(onClickListener);
vBottom.setOnClickListener(onClickListener);
No need to add more proguard rules, consumerProguardFiles
has already handled library proguard rules.
- Please check the demo before use.
- If this project helps you, please star me.
The MIT License (MIT)
Copyright (c) 2019 FloatingView
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.