Comments (6)
Hi @sianyi
Thanks for trying out this library
First of all, could you explain what kind of behavior you want to achieve?
- Is it a simple TextView that floats (and drag-able) inside an Activity / Fragment? Or inside a CustomView? Where does the
InitialTextView()
being called from? - Then, does the TextView has to be inflated / created programmatically?
If the answer of first question is inside activity or fragment & the second question is true, as far as i know, we have to add the TextView to ViewGroup inside the activity / fragment layout
So, assuming you have this layout and activity code
<!-- activity_example.xml -->
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Other View or ViewGroup -->
</RelativeLayout>
We have RelativeLayout root with root_view
as it's id
// ExampleActivity.java
public class ExampleActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_example);
InitialTextView();
}
private void InitialTextView(){
TextView floatingLuxView = new TextView(this);
floatingLuxView.setText("Hi I am a overlay View");
floatingLuxView.setTextColor(Color.rgb(255, 255, 0));
floatingLuxView.setTextSize(32f);
floatingLuxView.setShadowLayer(10, 5, 5, Color.rgb(56, 56, 56));
DraggableUtils.makeDraggable(floatingLuxView);
WindowManager windowManager = (WindowManager)getSystemService(WINDOW_SERVICE);
int LAYOUT_FLAG;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
LAYOUT_FLAG = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
} else {
LAYOUT_FLAG = WindowManager.LayoutParams.TYPE_PHONE;
}
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
LAYOUT_FLAG,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.TOP|Gravity.LEFT;
// We need to add this floatingLuxView to any ViewGroup on the layout
// in this case i'm adding it to the root_view
ViewGroup rootView = findViewById(R.id.root_view);
rootView.addView(floatingLuxView);
}
}
We have the InitialTextView()
function inside the activity and is being called from onCreate()
,
then we just need to add the floatingLuxView
to the rootView
If that's the behavior you'd expect, it would be easier to just write the TextView
directly on the xml code, so you don't have to deal with attaching / inflating it to the layout manually.
As for the crash issue, i've tried the code you provide without above modification (adding it to the rootView
whatsoever), inside a simple activity, but i can't reproduce the crash.
It runs, the TextView doesn't show up, but it doesn't crash. Could you show me your full code of your implementation?
from draggableview.
Hi I make a simple app for your reference
https://github.com/sianyi/example_of_floating_lux
I would like to show a floating text view on top of screen and overlay others application.
In addition, I hope it is Draggable.
In the simple APP you can see the red color TextView is inside the main Activity and it works well but the yellow color textView is overlay on other application and will rise Exception when I touch it.
from draggableview.
Hi @sianyi
I updated the library to support the case of overlay draggable view over other app via makeOverlayDraggable()
. Can you please check version 0.5.0
out ?
I've also updated the readme regarding it's usage example
Here's the preview on emulator (there's no light sensor on emulator so the value stays 0.0)
On a sidenote, i can't make it work on API 19 (Kitkat) device, the overlay was removed as soon as the activity goes into background. I haven't tried it on a Service
though.
from draggableview.
Thanks!, it is really help.
I will try it.
from draggableview.
It might take a while for the updated version to appear on JitPack (several minutes maybe, but it shouldn't take long)
from draggableview.
I have tested the new version and it works well on my devices, thank you very much.
from draggableview.
Related Issues (14)
- Create helper to extend the behaviour to any view HOT 2
- How to make draggable webview using this ?
- Is there a function to resize the ImageView while on dragging? HOT 1
- How to drag over other items?
- OnLongClickListener not working HOT 1
- Unable to implement for CameraX PreviewView HOT 3
- Convert lib to java HOT 2
- OnPositionChangedListener HOT 1
- implementation in scroll view? HOT 2
- disable drag
- View not dragging when it was on bottomsheet. HOT 1
- how can i maintain view position while orientation change ?
- how to change its view position by passing value of x and y ?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from draggableview.