View myView = findViewById(R.id.my_view); float translationX = myView.getTranslationX(); Log.d("TAG", "TranslationX: " + translationX);
View myView = findViewById(R.id.my_view); myView.setTranslationX(50f); float translationX = myView.getTranslationX(); Log.d("TAG", "TranslationX: " + translationX);In this example, we are setting the horizontal translation of the view with the ID "my_view" to 50 pixels and then getting and logging the value. This method belongs to the android.view package library.