in Android how to make a view have same height as its screen size, is it possible to achieve this with only the xml? or if it must use script, tell me how
Thanks.
Sorry for being not clear, and thanks for your reply
but i think, match_parent and fill_parent attribute is not reliable, because when i put the view inside one container or change the view container hierarchy, it won't work.
Here my complete xml layout.
The element i want to make the height sam with device screen is the last list view inside relative layout
layout_width : the width, either an exact value, WRAP_CONTENT , or FILL_PARENT (replaced by MATCH_PARENT in API Level 8) layout_height : the height, either an exact value, WRAP_CONTENT , or FILL_PARENT (replaced by MATCH_PARENT in API Level 8) Parameters. c. Context : the application environment.
The size of a desktop computer monitor is determined by physically measuring the screen. Using a measuring tape, start at the top-left corner and pull it diagonally to the bottom-right corner. Be sure to only measure the screen; do not include the bezel (the plastic edge) around the screen.
No you cannot achieve this in XML only.
As Android supports multiple screen sizes, at runtime you need to check for each device size. The height for each device can be calculated like this:
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int height = size.y;
With the above code, you will get the height of the screen and you need to set this height in dp to your view at runtime.
Do this in your activity:
// get view you want to resize
LinearLayout mainLayout = (LinearLayout) findViewById(R.id.main);
// get layout parameters for that view
ViewGroup.LayoutParams params = mainLayout.getLayoutParams();
// change height of the params e.g. 480dp
params.height = 480;
// initialize new parameters for my element
mainLayout.setLayoutParams(new LinearLayout.LayoutParams(params));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With