I have the following layout in the url.
there are two linearlayouts inside a linear layout (above , below)(vertical) . in the LinearLaoyut above there are two LinearLayouts (horizontal)with a Image (left) and in the other one TWO TextViews (right)...
I want them to set their height and weidth in reference to the screen size.
How can I do it concerning this example?
Related
How to actually create a matrix of buttons to cover the entire screen programmatically.
What I tried : I am currently able to create buttons but I want them to occupy the entire screen area, they are just occupying top left part
You can use a TableLayout or LinearLayout too assigning weights in your Buttons.
Let's use a LinearLayout. This can be done both in xml and in your class. Let's create a 2 by 2 matrix of buttons.
Add a LinearLayout with any orientation (let's use horizontal)
Add 2 LinearLayouts inside with opposite orientation of number 1 (in this case we use vertically. Then we set the width=0dp and layout_weight=1 for both to occupy equal spacing)
Now we can add our buttons inside the vertical oriented LinearLayouts and set their height=0dp and layout_weight=1 for them to have equal sizes.
That's it. using the TableLayout is a cheaper way if you have more rows and columns
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.
Suppose there are two Button in TableLayout and if I mention android:layout_span="1" in both the button then the complete width is divided into two part and each button sit into one part.
Can we achieve this same thing for height.
In my application four button is there which arranged in linear order one on the top of other.
I want all these four button cover complete height of the screen in any size of screen.
My Problem is here if I launch this screen on one device then it look like:-
But if I launch this layout on big screen then it looks like:-
How on all the screen the button cover(uniformly distribute)?
Set the layout height for each view to be 0 and instead use layout weight. Use the value 1 for layout weight for all the buttons for them to be equally spaced!
I have to make a layout like in the figure below (Each block in the 3 x 3 grid would be a ImageButton and each of the ImageButton has text and a small image in the bottom):-
I think i can use a TableLayout, but the problem is that I want to fit all the components in a single screen without any extra scrolling. When I used LinearLayout, the imageButtons where overlapping each other, how do I avoid it?
I want the ImageButtons to fill up the width of the screen, but match_parent is not helping. Should I fix the size of the ImageButtons. But I want the layout to work in all the screens, not specifically in only one.
If I include the buttons also in the TableLayout (as a separate rows), then they are of the size of the ImageButton, wrap_content is not effective. And I dont know how to place them in the centre.
Please suggest something. Any other layout suggestions? I am not using GridLayout because the App is for GingerBread (Android API 10).
Thank you.
I would use:
- Linear layout, orientation: vertical - as an external layout
- Linear layouts, orientation: horizontal - for each line. Set layout weight for any of the 3 "items" in it to be 33.
Each item consisting of: image button, text and image - a linear layout, orientation: vertical, and the text & image: again, a linear layout, orientation: hortizontal.
Image Button: set width to fill_parent. You can match height accordingly.
I am creating a number of imageviews and textviews on runtime depending on the objects in my webservice. I'm creating linearLayout horizontal and adding imageviews and textviews to layout, now the issue is the text are against images, and images are of different width so i want to set x position of my textviews so they all look align how can this be done,
i tried absolutelayout(warning deprecated) , setx(no method showed)
you can use resized image on runtime based on the pannel height and width for resizing image on runtime view this stack overflow thread
resizing image java getScaledInstance
I presume you mean this is a vertical LinearLayout, and each text/image combo is added below the previous one? In that case, you could have two LinearLayouts next to each other like two columns, adding the images to one and the text fields to the other. Then the widest image would stretch its layout to that width and all text fields would be just to the right of it.
Use weight property in your ImageView and TextView