I have a ListView whose single item have a RelativeLayout which contains many elements , now i have RelativeLayout set to wrap_content in height and a certain width. What i want to display is horizontally center the RelativeLayout. ListView spans horizontally and vertically to full as it has also wrap_content in height and width.
Also i don't want to include another layout.
Change RelativeLayout width to match_parent. and manage all inner views as yout require.
Related
I want to give responsive height to children in a vertical Linearlayout for example(some view height must be 25% of the screen height) I know this is simple if I use weight but the problem is that I have the LinearLayout inside a ScrollView this means I dont know the exact height of the LinearLayout so weight doesn't work here.can anyone give me a way to do so.
Use:
scrollView.setFillViewport(true)
This way, the linear layout inside occupies the full height.
Please look at following 2 layouts.
First, cardview:
http://pastebin.com/iYzUiDQ7
Second, LinearLayout only (layout is actually the same as the one inside my CardView):
http://pastebin.com/xijHZCPw
So, second layout contains WebView component + single LinearLayout under it that should represent the same layout as single CardView item.
It works, however... I'm having problems with scaling images. If I set very large image as image for my ImageView placed on CardView, it will be scaled nicely to fit on my CardView. CardView's height won't be changed, instead, image will be scaled proportionally to fit.
But when I'm trying to do the same with second layout I linked, my LinearLayout changes its height if I set large image. How should I change my second layout to get the same effect for my LinearLayout, placed at bottom of my screen?
I get the difference between the two layout.
you had set the layout_height with 100dp in CardView. so the height of LinearLayout in CardView will does not beyond that. But you set the layout_height with wrap_content in you second LinearLayout.
Try to set maxHeight or layout_height with digit to deal with you problem.
Hope this can help you.
I have a fixed number of elements, 3 to be precise, aligned horizontally in a SINGLE row, in my GridView.
Each Grid Element is a Linear layout with vertical orientation.
//Fixed Size NOT OPTIONAL
//Optional text
//optional text
//optional text
//NOT OPTIONAL
As text1/text2/text3 are not compulsory, each GridElement has variable height. If the height of first GRIDELEMENT is less than the other two GRIDELEMENTS, the heights of GridElements two and three are cut as the GridView takes the height of the first element.
I want the GridView to take the height of the tallest element.
Please help me in resolving this issue.
I have a bar in the bottom of my layout which consists in a horizontal LinearLayout (like a row) that contains vertical LinearLayouts (Like a cell of a row).
The Horizontal linearLayout (row) haves WRAP_CONTENT height because i want the bar fit its elements height, and the vertical linear layouts (cells) have MATCH_PARENT because they can have for example a item centered vertically inside,
so they are MATCH_PARENT and they must have the Height of the higher height of the cells on the row.
The problem is that the bar is occupying all the height of my screen. I think that there are problems with MATCH_PARENT inside a WRAP_CONTENT.
How can i solve this problem?
To set MATCH_PARENT height to LinearLayouts(cells) you must have to fix some height of row(LinearLayout) otherwise it will covers entire screen
If I try to center the current view vertically within its parent. Which one should I use?
I saw TextViews use gravity="center_vertical" and ImageViews uselayout_centerVertical="true".
I am not sure why?
In textview , gravity="center_vertical" means the content in the textview will be center and vertical . you can only see the alignment of text if textview is fill_parent if its wrap_content then there will be no place for content to have alignment.If you use layout_gravity here and width and height to wrap_content then it will place the textview in the center _vertical of the parent layout.
In imageview ,layout_centerVertical="true". means place iamge and in center and vertical in the parent layout of image (i.e the container of image).