0

I have animation working with tabsView, when the tabs are changed, the icons of these tabs move to the center with distance of int 54 which is transformed into dp-s shown below, and I have also indicator moving the distance of 70dp the same way, the problem is that animation works perfectly, but the distance is the same for all screen sizes which looks bad for small or too big screens, so is there any way to replace these distances using MATCH_PARENT variable so that result would be same for all screen sizes?

 IndicatorTranslationX = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,54,getResources().getDisplayMetrics());
 endViewsTranslationX = (int) ((mCenterImage.getX() - mStartImage.getX()) - IndicatorTranslationX);
 newTranslationX = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,70,getResources().getDisplayMetrics());
 mIndicator.setTranslationX((positionOffset -1) * newTranslationX);
Cybber
  • 61
  • 3

1 Answers1

0

Use DisplayMetrics to get width and height of the device screen.

See this question

Juan
  • 5,525
  • 2
  • 15
  • 26