RelativeLayout layout = findViewById(R.id.main_layout); int height = layout.getHeight();
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); params.height = ViewGroup.LayoutParams.WRAP_CONTENT; params.width = ViewGroup.LayoutParams.MATCH_PARENT; button.setLayoutParams(params); int height = button.getHeight();In this example, we set the layout parameters of a button to match the parent width and wrap the content height. Then we retrieve the height of the button using the getHeight method. The package library associated with this method is "android.view".