TextView myTextView = findViewById(R.id.myTextView); myTextView.setPadding(5, 5, 5, 5);
LinearLayout myLayout = findViewById(R.id.myLayout); myLayout.setPadding(10, 20, 30, 40);In this case, the top and bottom padding is 20 and 40 pixels respectively, while the left and right padding is 10 and 30 pixels respectively. The setPadding() method is part of the android.view.View class in the Android framework.