I have 3 FrameLayout in my layout, the first and the third have a fixed height (wrap_content of child views).
And I want the second FrameLayout to fill remaining space between the first and the third element.
My XML :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<!-- ... childs views with fixed height -->
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp" <!-- Fill remaining space -->
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp" >
<!-- ... childs views with match_parent height -->
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<!-- ... childs view with fixed height -->
</FrameLayout>
</LinearLayout>
you can use the layout_weight="1" property for the central FrameLayout, leaving 0dip for the height. It will the take the space left from the other two
Related
I am trying to make android screen with three LinearLayouts. The parent LinearLayout's weightsum is 10 and I give child LinearLayout's weight as ( 1.5 , 7.5 , 1 )
I thought LinearLayout's size would be fixed, but When I try to put some view elements in the child LinearLayouts, the child LinearLayout's size changes depending on the element inside.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/light_black"
android:weightSum="10"
tools:context=".userRegisterActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.5"
android:weightSum="10"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="7.5"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
if I put TextView elements in the child LinearLayout, the sizes are changing... How to make it fix?
I got the answer.
the android:layout_height property must be '0dp' not match_parent
So I have a ExpandableListView in my layout, but for some reason It is showing only some part of it when I run the app. Yes, it's "some" part - actually almost the enture first GroupView.
If I set a fixed height to the list at android:layout_height="some dp", instead of android:layout_height="match_parent" I can see the whole list. But, If I have too many group view's and child view's, again, I can see only some part of it (as the height is fixed).
I've tried to put the expandable list inside a LinearLayout, have tried to set android:layout_height="wrap_content", and so on, but without success.
How can I solve this?
Thank you,
<?xml version="1.0" encoding="utf-8"?>
<!-- That's the main layout.-->
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroll_view_m"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- This LinearLayout is here because a ScrollView can only have one child view.-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- That's the second ScrollView. But this one is horizontal.-->
<HorizontalScrollView
android:id="#+id/map_layout"
android:layout_width="match_parent"
android:layout_height="400dp">
<!-- This LinearLayout is here because a ScrollView can only have one child view.-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<!-- Some view's here -->
</LinearLayout>
</HorizontalScrollView>
<TextView
android:id="#+id/scroll_down"
android:text="Scroll down to see marker info!"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/holo_green_light"
android:background="#android:color/black"/>
<ExpandableListView
android:id="#+id/m_expandable_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ExpandableListView>
</LinearLayout>
</ScrollView>
I have a LinearLayout with a ScrollView inside and a checkbox underneath the scrollview. Whenever i put alot of text in the scrollview, it will expand through the whole screen and kick out the bottom checkbox view. How do i prevent that from happening?
Basically, i want the checkbox to always be right underneath the scrollview. I also want the scrollview to shrink and expand depending on its text. When theres alot of text inside, it should expand to the point where the checkbox is still visible at the bottom of the screen.
It should look like this:
Where the filled ScrollView should have a scroller if the text is too much, rather than kicking out the checkbox from the screen
Help!
My layout looks like:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- TextView inside --->
</ScrollView>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="80dp"
android:gravity="top"
android:orientation="horizontal" >
<!-- CheckBox inside --->
</RelativeLayout>
</LinearLayout>
Dont worry about the syntax, or all the stuff that are inside, I wrote this quick because the code inside is really long and unnecessary!
Try this layout :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1">
<!-- TextView inside --->
</ScrollView>
<!-- CheckBox Here --->
</LinearLayout>
Let's start simple. Try replacing your parent LinearLayout with a RelativeLayout. If this doesn't work, you may have to fix the height of ScrollView to some fixed height using weight, or pixels (which is non-ideal):
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- TextView inside --->
</ScrollView>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="80dp"
android:gravity="top"
android:orientation="horizontal" >
<!-- Stuff inside --->
</RelativeLayout>
</RelativeLayout>
Define a fixed size to your ScrollView. As bigger as the text becomes, the scroll is defined to that size (like layout_height="100dp")
UPDATE
Try something like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="200dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<!-- TextView's inside - -->
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- CheckBox's inside - -->
</LinearLayout>
</LinearLayout>
I am trying to create a HorizontalScrollView which will be exactly 3 times the screen width. I have tried the following code, but the scrollview will not scroll. How can I set it so that the 3 LinearLayouts inside the main LinearLayout are each the width of the screen?
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<!-- the container for all the pages -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#000000"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#FF0000"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#FF0000"/>
</LinearLayout>
Note that if I give the LinearLayouts a specific width, the scrollview does scroll, but I need each LinearLayout to have the width of the screen.
You will need to use wrap_content on your top LinearLayout, and set the width of the child LinearLayouts programmatically.
I have a layout as below
<LinearLayout
android:id="#+id/home_screen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="#+id/slide_pager"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="0dp" >
</android.support.v4.view.ViewPager>
<RelativeLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:visibility="visible" >
< .. views />
</RelativeLayout> </LinearLayout>
When I am setting the height of RelativeLayout footer to say 200dp , I see the ViewPager .If the footer is 'wrap_content' the ViePager is fully disappeared. I tried setting weight of ViewPager to 1 but of no use . I want the footer to be wrap_content. and ViewPager to occupy the remaining space.
thank you.
The issue is same even after setting layout_height to wrap_content.
If in a vertical LinearLayout, you set the width to 0dp, then it is not going to shown. Also happens in a horizontal LinearLayout and 0dp of height.
Just change the width to wrap_content (or whatever else).
The problem is that we have to supply the weight to child layouts according to its requirement. So I set weight for viewpager to .75 and to remaining layout to .25 and now the view pager will be displayed to 3/4th of the screen.
<LinearLayout
android:id="#+id/home_screen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="#+id/slide_pager"
android:layout_width="match_parent"
android:layout_weight=".75"
android:layout_height="0dp" >
</android.support.v4.view.ViewPager>
<RelativeLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight=".25"
android:visibility="visible" >
< .. views />
</RelativeLayout> </LinearLayout>