How to set the x position of views in android - android

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

Related

CardView vs LinearLayout - images scalling issue

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.

android GridLayout divider row

I'm trying to implement a tabular layout that has a header and a bunch of rows underneath it. I've chosen the GridLayout (android.support.v7.widget.GridLayout) as there's some requirements for some elements to span multiple columns (but those are of no concern to the question).
My header cells each contain a LinearLayout with a bunch of TextViews, they're dynamically filled in code,for the sake of example, have a look at the image below.
The second row should contain the divider which is a simple view, that should span my header columns (3).
The problem is the width of the divider - if I choose MATCH_PARENT, it will push the GridLayout to fill the whole remaining space to the right. The grid needs to wrap the content and center itself horizontally. It seems to me there's a conflict between the grid's layout (WRAP_CONTENT) and the divider's layout (MATCH_PARENT).
How can I fix the width of the divider without hardcoding it?
http://i61.tinypic.com/2415eg5.png
In red, my LinearLayouts (header), green, the GridLayout itself, the thin blue line at the bottom is the divider.
Thanks,
MO
SOLUTION (as provided below):
I had to set the column weight for the divider to 1, without specifying a width (actually setting it to zero). Because of my specific requirement to handle all of these in code, the solution was to manually instantiate the GridLayout.LayoutParams class and use
ColumnSpec = GridLayout.InvokeSpec(row_index, num_spanned_cols, weight)
Hope this helps others in the future.
If you set the width to 0dp then give it android:layout_weight="1"
(you could give it any weight you want) it should fill all the available space and not push your bounds if I understand what you are asking correctly

Set LinearLayout in reference to screen size?

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?

How to fix the size of cells in a tablelayout in android

How do you fix(prevent them from moving) the size of cells in a tablelayout in android?
I have a tablelayout with image buttons inside each cell, the problem is, when I change (or remove) the image, the size of the button changes. How do I prevent this?
Set each View’s layout_width equal to 0.
Add in each View layout_weight, according to your needs
Reference : http://pournaras.zilsen.com/2010/11/01/fixed-column-width-in-tablelayout/

Designing a layout with multiple ImageButtons and Buttons

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.

Categories

Resources