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.
Related
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;
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.
In framelayout, if I want to put a view in the position that starts from 1/2 of the screen width. How can I do it? Thanks.
You can accomplish that in multiple ways. It only depends if you really need to stick with the FrameLayout.
Two easiest would be those:
FrameLayout - you would need to know whats the width of the layout (so if your layout is wrap_content it might get tricky). Set your view's gravity to left, and set its margin_left to half of the layout's width.
LinearLayout - either put it inside your FrameLayout (not very good practice), or (if you can) swap it with your FrameLayout. Set it's orientation to horizontal, add dummy view with width = 0dp, weight = 1. Then add your view with the same values for width and weight.
How do I make listview height take all available space on screen, even if there is only one item on the list that is 100dpi tall?
Simply set the width and height of the ListView like this :
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
use match_parent as width and height, and also make sure your background image (if you're using one) is not limiting the height. In that case, if your bg image is larger, the height will go higher and same if smaller. If that's the case, then you should move your background to a parent view like a FrameLayout or a LinearLayout
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