Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android equivalent work-around for View.getX() before API 11?

I'm using the getX() and getY() method on a view for some special dragging logic (not animation, i.e. I never use setX/Y methods, I just need the getters to check).

However, I've come to realize that these are only available post-API 11.

The docs for getX() say that is it the addition of the 'left' property and the 'translationX' property. All well and good, except get/setTranslationX() is only around since API 11 as well.

I was wondering if there was any knowledge on what this method returns behind the scenes, so I could maybe put in a workaround.

like image 939
cemulate Avatar asked May 31 '12 20:05

cemulate


3 Answers

Use nineOldAndroid.jar file in your project And use this way

import com.nineoldandroids.view.ViewHelper;


ViewHelper.setTranslationX(myView, translation);

ViewHelper.getX(myView);
like image 110
Dipendra Avatar answered Nov 15 '22 17:11

Dipendra


How about getLeft() and getTop(). Looks to me like these are valid as long as the view hasn't been translated (setTranslationX() and setTranslationY()) which also aren't valid in the older API.

like image 20
Doug Gerecht Avatar answered Nov 15 '22 19:11

Doug Gerecht


Using android.support.v4.view.ViewCompat the solution is:

ViewCompat.getY(mView);

which is compatible with old android devices.

like image 26
Roberto Tellez Ibarra Avatar answered Nov 15 '22 18:11

Roberto Tellez Ibarra