TextView myTextView = new TextView(this); myTextView.setText("Hello World"); myTextView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); myTextView.setGravity(Gravity.CENTER); // set the left position of text view at 50 pixels myTextView.setLeft(50); // add the text view to its parent view parentView.addView(myTextView);
ImageView myImageView = findViewById(R.id.imageView); int leftPosition = myImageView.getLeft(); // get left position of image view Toast.makeText(getApplicationContext(), "Left position: "+leftPosition, Toast.LENGTH_LONG).show();The package library for android.view.View is android.view.