Hello at runtime, you can find out this way, it will return the Width & Height
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int height = displayMetrics.heightPixels;
int width = displayMetrics.widthPixels;
In a view you need to do something like this:
((Activity) getContext()).getWindowManager()
.getDefaultDisplay()
.getMetrics(displayMetrics);
If it worked for you, remember to give it up but say what was the result to continue helping you.
Greetings !!
EDITING
I initially thought you only needed to know the limits of the screen and clearly I was wrong with what you needed.
About the bookstore I have no experience but I feel committed to support you.
Investigate the code of the library and it does not have a method that returns the arrangement of Images, in the library they are called "Particles" or particles. There is an image for each particle. But the Particle class if it returns the X and Y.
Look at this sample code:
public class MainActivity extends AppCompatActivity {
private Button btnDisparar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
btnDisparar = findViewById(R.id.btnDisparar);
btnDisparar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ParticleSystem p = new ParticleSystem(MainActivity.this, 1, R.drawable.ic_drop, 2000);
p.setSpeedByComponentsRange(0f, 0f, 0.5f, 1f);
p.setAcceleration(0.00005f, 90);
p.emitWithGravity(findViewById(R.id.btnDisparar), Gravity.BOTTOM, 1);
p.addModifier(new ParticleModifier() {
@Override
public void apply(Particle particle, long miliseconds) {
float x = particle.mCurrentX;
float y = particle.mCurrentY;
Log.i("Particle # ", "X = "+ x);
Log.i("Particle # ", "Y = "+ y);
}
});
}
});
}
}
The Logcat shows the following:
I/Particle #: X = 181.0
12-04 09:04:02.494 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: Y = 282.0
12-04 09:04:02.544 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: X = 181.0
12-04 09:04:02.544 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: Y = 404.7401
12-04 09:04:02.594 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: X = 181.0
12-04 09:04:02.594 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: Y = 527.7302
12-04 09:04:02.644 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: X = 181.0
12-04 09:04:02.654 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: Y = 650.97034
12-04 09:04:02.694 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: X = 181.0
12-04 09:04:02.704 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: Y = 774.46045
12-04 09:04:02.744 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: X = 181.0
12-04 09:04:02.744 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: Y = 898.20056
12-04 09:04:02.804 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: X = 181.0
12-04 09:04:02.804 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: Y = 1022.1907
12-04 09:04:02.854 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: X = 181.0
12-04 09:04:02.854 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: Y = 1146.4308
12-04 09:04:02.904 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: X = 181.0
12-04 09:04:02.904 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: Y = 1270.9209
12-04 09:04:02.954 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: X = 181.0
12-04 09:04:02.954 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: Y = 1395.661
12-04 09:04:03.004 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: X = 181.0
12-04 09:04:03.004 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: Y = 1520.6511
12-04 09:04:03.054 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: X = 181.0
12-04 09:04:03.054 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: Y = 1645.8912
12-04 09:04:03.114 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: X = 181.0
12-04 09:04:03.114 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: Y = 1771.3813
12-04 09:04:03.154 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: X = 181.0
12-04 09:04:03.154 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: Y = 1897.1215
12-04 09:04:03.214 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: X = 181.0
12-04 09:04:03.214 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: Y = 2023.1116
12-04 09:04:03.254 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: X = 181.0
12-04 09:04:03.254 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: Y = 2149.3516
12-04 09:04:03.314 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: X = 181.0
12-04 09:04:03.314 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: Y = 2275.8418
12-04 09:04:03.354 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: X = 181.0
12-04 09:04:03.354 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: Y = 2402.5818
12-04 09:04:03.414 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: X = 181.0
12-04 09:04:03.414 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: Y = 2529.572
12-04 09:04:03.454 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: X = 181.0
12-04 09:04:03.464 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: Y = 2656.812
12-04 09:04:03.514 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: X = 181.0
12-04 09:04:03.514 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: Y = 2784.3022
12-04 09:04:03.554 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: X = 181.0
12-04 09:04:03.564 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: Y = 2912.0422
12-04 09:04:03.604 20820-21314/com.labs.ejemplolibreriaanimacion I/Particle #: X = 181.0
In the code what I programmed basically, is that a single particle falls every second.
How you can notice X = 181.0 and Y varies and increases until it dies and another particle with the same X appears.
What I recommend is that you download the GitHub library and implement the necessary methods in the Particle class to define "existence" limits based on the properties mCurrentX
and mCurrentY
, that is, if it reaches a certain point in the screen that changes animation and then disappears.
I hope I have better complemented my response.