Android Dynamically changing one child Layout height - android

I wanted to make a layout which has three children layout.
the bottom layout must visible to bottom
screen size is enough:
the center layout need Dynamically change to wrap_content and we need the bottom layout is under the center layout (not top of the parent).
screen size is not enough:
fix size of center layout will fixed and it is a scrollview, it's height is dependency on the reminding width(if screen size is not enough)
I think a lot of ideas but i don't know how can do using xml. It can be only calculate in runtime?
this is the intend image:

you can use wrap_content in xml
OR
To change programatically you can use following code
Your_Layout.getLayoutParams().height = 100;

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 app - make view only take up portion of parent view

I have a background image on my app, and I want my listview to be in the form of a window that overlays the background image. Sort of like the the form which has a white filter in this picture:
http://25.media.tumblr.com/ad75c4a9dad9650ed53d754712f4fbb2/tumblr_mgemxiU2W01r2wjwko2_1280.png
I currently have a listview defined in xml with:
android:layout_width="fill_parent"
android:layout_height="fill_parent"
and a semi transparent color as its background. This is great, but it takes up the whole screen, since it fills the parent width and height. What is the best way to make it slightly smaller than the parent's dimensions so that it is say, (fill_parent - some relative value) height and width?
Use margin in a layout to make it smaller relative to the parent layout and other child's
Use a FrameLayout as a parent, then add your ListView and set width and height to wrap_content. Now it should "float" above the other views inside the FrameLayout. You can use padding and margin to set its position.

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.

Make last view fit to bottom of screen

is there any possibility to change the properties of the last view in the layout to change its size to fit to the bottom of the whole screen (in any screen density).
Here is a sample image of my layout:
The layout contains a ScrollView with a LinearLayout as only child. The last item in this LinearLayout is a TableView with a grey gradient as background.
You can try setting layout_height of your items to "fill_parent" and change their sizes via changing layout_weight property, that should work.
If you want the grey part to stick to the bottom you should put weight=1.0 and wrap content for height on the view that is above that one (the white area).
Checked it again on similar layout. The main work does the property android:fillViewport="true" Which
Defines whether the scrollview should stretch its content to fill the viewport
More infos: ScrollView.html#attr_android:fillViewport

Android - How to place an item on a layout relatively to the top?

How could I proceed to place an item on a LinearLayout, with a given space from the top? For instance, I would like to place the logo on the half of the top middle of the layout.
Thanks
There is no way to add percentages.
You can add two layouts with the same weight to split the screen in two and then add the logo with a centered gravity to the upper layout,
Or you can measure the screen and add the right amount of margins.
Use the paddingTop attribute of the view class.

Categories

Resources