android - LinearLayout (Horizontal) - auto space between items - android

I have an android LinearLayout and at the button I have buttons that I want to display in one line - I've put the in a horizontal layout so it will be next to each other - so far so good.
Here is my problem - the buttons are right next to each other, and what I would like is to have them take the screen with spaces between them and padding from the right and left to the first and last buttons are not stuck to the border of the screen.
here's my layout xml (just the LinearLayout (Horizontal) part):
<LinearLayout
android:id="#+id/btnHelpLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:layout_gravity="center_horizontal"
android:orientation="vertical" >
<Button
android:id="#+id/btnHelp"
android:layout_width="52dp"
android:layout_height="52dp"
android:background="#drawable/btn_help" />
<TextView
android:id="#+id/tvHelp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="#string/btn_help"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:id="#+id/btnShareLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:layout_gravity="center_horizontal"
android:orientation="vertical" >
<Button
android:id="#+id/btnShare"
android:layout_width="52dp"
android:layout_height="52dp"
android:background="#drawable/btn_share" />
<TextView
android:id="#+id/tvShare"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="#string/btn_share"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:id="#+id/btnAboutLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="28dp"
android:layout_gravity="center_horizontal"
android:orientation="vertical" >
<Button
android:id="#+id/btnAbout"
android:layout_width="52dp"
android:layout_height="52dp"
android:background="#drawable/btn_about" />
<TextView
android:id="#+id/tvAbout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="#string/btn_about"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:id="#+id/btnSettingsLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical" >
<Button
android:id="#+id/btnSettings"
android:layout_width="52dp"
android:layout_height="52dp"
android:background="#drawable/btn_settings" />
<TextView
android:id="#+id/tvSettings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="#string/btn_settings"
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>
how can I have it centered and with spaces?
thanks

Change the child container's (the LinearLayout's btnHelpLayout, btnShareLayout, btnAboutLayout and btnSettingsLayout) android:layout_width attributes to "0dip" and set a new attribute android:layout_weight="1" in all child containers (Not the Buttons and TextViews).
This will make them occupy the same space and give you a uniform look.
<LinearLayout
android:id="#+id/btnHelpLayout"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="30dp"
android:layout_weight="1"
android:orientation="vertical" >
<Button
android:id="#+id/btnHelp"
android:layout_width="52dp"
android:layout_height="52dp"
android:background="#drawable/btn_help" />
<TextView
android:id="#+id/tvHelp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="#string/btn_help"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:id="#+id/btnShareLayout"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="30dp"
android:layout_weight="1"
android:orientation="vertical" >
<Button
android:id="#+id/btnShare"
android:layout_width="52dp"
android:layout_height="52dp"
android:background="#drawable/btn_share" />
<TextView
android:id="#+id/tvShare"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="#string/btn_share"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:id="#+id/btnAboutLayout"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="28dp"
android:layout_weight="1"
android:orientation="vertical" >
<Button
android:id="#+id/btnAbout"
android:layout_width="52dp"
android:layout_height="52dp"
android:background="#drawable/btn_about" />
<TextView
android:id="#+id/tvAbout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="#string/btn_about"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:id="#+id/btnSettingsLayout"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:orientation="vertical" >
<Button
android:id="#+id/btnSettings"
android:layout_width="52dp"
android:layout_height="52dp"
android:background="#drawable/btn_settings" />
<TextView
android:id="#+id/tvSettings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="#string/btn_settings"
android:textColor="#fff" />
</LinearLayout>

Related

How can I place the text on the image in variable devices?

Hi, I make application with this Image.
I want place the text on red dot points at lines left side and right side.
So I place the text on point, but when I change the device Galaxy S6 to S8,
text placement depart from lines.
I seperate the lines and put weight on it, but still out.
How I can place the text on that image in variable device?
Please help me.
This is my layout.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="#drawable/nursecategory"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<!--first line-->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="32dp"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date"
android:textColor="#color/colorCategory"
android:textStyle="bold"
android:layout_alignParentRight="true"
/>
<TextView
android:id="#+id/nursetree_textview_Date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="6dp"
android:textAlignment="center"/>
</LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Age"
android:textColor="#color/colorCategory"
android:textStyle="bold" />
<TextView
android:id="#+id/nursetree_textview_Age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="6dp"
android:textAlignment="center"
/>
</LinearLayout>
</LinearLayout>
<!--second line-->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="24dp"
>
<!--Name-->
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:textColor="#color/colorCategory"
android:textStyle="bold" />
<TextView
android:id="#+id/nursetree_textview_Agency"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="6dp"
android:textAlignment="center"
/>
</LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<!--width-->
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Width"
android:textColor="#color/colorCategory"
android:textStyle="bold" />
<TextView
android:id="#+id/nursetree_textview_Width"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="6dp"
android:textAlignment="center"
/>
</LinearLayout>
</LinearLayout>
<!--third line-->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="26dp"
>
<!--place-->
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Place"
android:textColor="#color/colorCategory"
android:textStyle="bold" />
<TextView
android:id="#+id/nursetree_textview_Place"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="6dp"
android:textAlignment="center"
/>
</LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<!--heigth-->
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Height"
android:textColor="#color/colorCategory"
android:textStyle="bold" />
<TextView
android:id="#+id/nursetree_textview_Height"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="6dp"
android:textAlignment="center"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</LinearLayout>
use Relativelayout as parent layout then try to design your view.
in Relaytivelayout we can add layouts as tray. and it easily to handle.
also read about Relativlayout.

How can I give my widgets' width a percentage rather than an explicit value?

Based on how XAML works, I thought I could give my android widgets a percentage value for width. After searching, I found that *theoretically," this is available via the "layout_weight" property. But using this does not produce the desired appearance. Specifically, this xml:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<Spinner
android:id="#+id/spinnerUPCPLU"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".40"
android:entries="#array/delivery_upcplu_spinner" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextUPCPLU"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".90"
android:editable="false" />
</LinearLayout>
</LinearLayout>
...gives me this:
I can brute-force the layout to look more-or-less as I want it using explicit width values, like so:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<Spinner
android:id="#+id/spinnerUPCPLU"
android:layout_width="160dp"
android:layout_height="40dp"
android:entries="#array/delivery_upcplu_spinner" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextUPCPLU"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:editable="false"
android:minWidth="200dp" />
</LinearLayout>
</LinearLayout>
...which looks like this:
...but doing this (assigning specific dp vals to the width) makes me more nervous than a cat in a roomful of rocking chairs.
Is there balsam in Gilead? I mean, is there, after all, a way to assign percentage widths (that actually works, of course)?
Am I using layout_weight wrong, or am I using the wrong methodology, or is it (perish the thought) impossible?
UPDATE
The accepted answer worked in one instance, but in the next:
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:text="#string/id"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editTextID"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:text="#string/pack_size"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editTextPackSize"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25" />
</LinearLayout>
...it doesn't:
It takes up half the width instead of all of it; must I put some "replace" talk in the EditText widgets for them to "widen out"?
I can "force it" by adding to the EditTexts:
android:minWidth="120dp"
...but that returns me to the nervosity level of the rocking-chair-room cat.
UPDATE 2
Now even what I thought was working is not, or no longer. The xml is this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="4dp"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="hhs.app.DeliveryActivity">
<!--Row 0-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp"
>
<Spinner
android:id="#+id/spinnerUPCPLU"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".10"
android:maxWidth="12dp"
android:entries="#array/delivery_upcplu_spinner"
/>
<EditText
android:id="#+id/editTextUPCPLU"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".90"
android:minWidth="1200dp"
android:editable="false"
/>
</LinearLayout>
<!--Row 1-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:text="#string/id"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextID"
android:layout_width="0dp"
android:minWidth="120dp"
android:layout_height="wrap_content"
android:layout_weight=".25" />
</LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:text="#string/pack_size"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextPackSize"
android:layout_width="0dp"
android:minWidth="120dp"
android:layout_height="wrap_content"
android:layout_weight=".25" />
</LinearLayout>
</LinearLayout>
...and it looks like this:
IOW, in the first row, the EditText is getting scrunched like a svelte trainer by an age-old elephant, and in the next row, the attempted equality of widths is not being observed (although it actually looks fine, those labels are not taking one-quarter of the width, but only what they need and no more).
And, the same is the case when I change ".25" to either "0.25" or "1" in all cases.
UPDATE 3
Okay, here is what I see with my LinearLayout with various combinations of "match_parent" and "wrap_content" for its "layout_width" and "layout_height" properties.
When both are set to wrap_content:
When both are set to match_parent:
If width is set to match_parent, and height is set to wrap_content, it is the same as when BOTH are set to match_parent
The other way around (with height set to match_parent and width set to wrap_content), it is the same as when BOTH are set to wrap_content
UPDATE 4
Here is the entire contents of this particular layout file, at its best, albeit not perfect by any means:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="4dp"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="hhs.app.DeliveryActivity">
<!--Row 0-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="5dp"
>
<Spinner
android:id="#+id/spinnerUPCPLU"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".10"
android:maxWidth="12dp"
android:entries="#array/delivery_upcplu_spinner"
/>
<EditText
android:id="#+id/editTextUPCPLU"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".90"
android:minWidth="1200dp"
android:editable="false"
/>
</LinearLayout>
<!--Row 1-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="25"
android:text="#string/id"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextID"
android:layout_width="0dp"
android:minWidth="120dp"
android:layout_height="wrap_content"
android:layout_weight="25" />
</LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="25"
android:text="#string/pack_size"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextPackSize"
android:layout_width="0dp"
android:minWidth="120dp"
android:layout_height="wrap_content"
android:layout_weight="25" />
</LinearLayout>
</LinearLayout>
<!--Row 2-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/desc"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="320dp" />
</LinearLayout>
</LinearLayout>
<!--Row 3-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/qty"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/orangeframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextQty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="144dp" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/count"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:editable="false"
android:minWidth="144dp" />
</LinearLayout>
</LinearLayout>
<!--Row 4-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/cost"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/orangeframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editCost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="48dp" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/margin"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/orangeframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextMargin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="48dp" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/list"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/orangeframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="48dp" />
</LinearLayout>
</LinearLayout>
<!--Row 5-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/dept"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<Spinner
android:id="#+id/spinnerDept"
android:layout_width="180dp"
android:layout_height="40dp"
android:entries="#array/departments" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="$"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextDollar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="48dp" />
</LinearLayout>
</LinearLayout>
<!--Row 6-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sub_dept"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<Spinner
android:id="#+id/spinnerSubdept"
android:layout_width="248dp"
android:layout_height="40dp"
android:entries="#array/subdepartments" />
</LinearLayout>
</LinearLayout>
<!--Row 7-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/box"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/delivery_invoice_number"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextDelivInvNum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:editable="false"
android:minWidth="124dp" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/vendor"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextVendor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:editable="false"
android:minWidth="124dp" />
</LinearLayout>
</LinearLayout>
<!--Row 8-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/total_dollars"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextTotalDollars"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="80dp" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/current_total"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextCurrentTotal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="80dp" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/qty"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/greyframe"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextReadonlyQty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="40dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<!--Row 9-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<Button
android:id="#+id/buttonSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/save" />
<Button
android:id="#+id/buttonFind"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/find" />
<Button
android:id="#+id/buttonClear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/clear" />
</LinearLayout>
</LinearLayout>
</ScrollView>
UPDATE 5
Okay, what I'm getting out of this is that the internal-most LinearLayouts need to be thus:
android:layout_width="match_parent"
android:layout_height="wrap_content"
...and all others (above them) thus:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
That works for the most part. But the EditTexts are too puny. If I remove the inner LinearLayouts completely, the EditTexts disappear (or have dimensions of 0?)
You should have a single LinearLayout containing all the "weighted" widgets.
Note that only 1 dimension at a time can be "weighted":
This is how I'd do that:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp"
>
<Spinner
android:id="#+id/spinnerUPCPLU"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".40"
android:entries="#array/delivery_upcplu_spinner"
/>
<EditText
android:id="#+id/editTextUPCPLU"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".60"
android:editable="false"
/>
</LinearLayout>
Note that the weight sum is 1 (android calculates it by itself).
I could set 4 and 6 or 40 and 60 - for Android that's always 100%, when summed.
You can optionally set a weightSum attribute in the Containing LinearLayout:
android:weightSum="1"
(or 10, or 100, ...)
If you want to (and your layout isn't complex), you can weight the other "dimension" (height in this case), too.
Just add another LinearLayout containing another Spinner and EditText.
Then enclose these 2 LinearLayouts in a third one.
Give both the children LinearLayouts a weight of 1 and a height of 0dp, so they will equally divide the container's height.
Some thing like that:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp"
>
<Spinner
android:id="#+id/spinnerUPCPLU"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="50"
android:entries="#array/delivery_upcplu_spinner"
/>
<EditText
android:id="#+id/editTextUPCPLU"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="50"
android:editable="false"
/>
</LinearLayout>
or
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp"
>
<Spinner
android:id="#+id/spinnerUPCPLU"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="70"
android:entries="#array/delivery_upcplu_spinner"
/>
<EditText
android:id="#+id/editTextUPCPLU"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="30"
android:editable="false"
/>
</LinearLayout>

Layout Weight in Linear Layout Android?

I am using two ListView in my Layout. and having fixed header and footer.But when i am running my code my header is getting breaked not coming full on my Device and my footer is not showing because of the ListView .
This is my main XML file that is having the ListView
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/llHeader"
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1">
<LinearLayout
android:id="#+id/mainLinearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#drawable/top_bg"
android:orientation="horizontal" >
<ImageView
android:id="#+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/back_btn"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="75dp"
android:text="Flights"
android:textColor="#android:color/white" />
</LinearLayout>
<LinearLayout
android:id="#+id/flightDetailsLayout"
android:layout_width="fill_parent"
android:layout_height="70dp"
android:layout_below="#+id/mainLinearLayout"
android:layout_centerHorizontal="true"
android:background="#drawable/gray_bg123"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/innerflightDetailsLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/from"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:paddingLeft="12dp"
android:textSize="12sp"
android:text="Boston to San Fransisco, "
android:textStyle="bold" />
<TextView
android:id="#+id/tripType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="RoundTrip"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/innerTripLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/tripDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="12dp"
android:textSize="10sp"
android:text="19 Jan 2013 "
android:textStyle="bold"/>
<TextView
android:id="#+id/paxText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="for 1 Adults,0 Childs,O Infants"
android:textSize="12dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/Book"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/tripDate"
android:layout_width="84dp"
android:layout_height="wrap_content"
android:paddingLeft="12dp"
android:text="Rs 10,2345 "
android:textSize="10sp"
android:layout_weight="1"
android:textStyle="bold" />
<ImageView
android:id="#+id/bookBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:src="#drawable/book" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/sortFlightLayouts"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/flightDetailsLayout"
android:background="#drawable/gray_bg123"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DEL-BLR"
android:layout_marginLeft="6dp"
android:layout_marginTop="5dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:src="#drawable/flight_icon_result" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="25dp"
android:src="#drawable/time" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:src="#drawable/rupee" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="60dp"
android:background="#android:color/darker_gray" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/gray_bg123"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BLR-DEL"
android:layout_marginLeft="6dp"
android:layout_marginTop="5dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:src="#drawable/flight_icon_result" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="25dp"
android:src="#drawable/time" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:src="#drawable/rupee" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="4"
android:orientation="horizontal">
<ListView
android:id="#+id/lvDepartures"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<ListView
android:id="#+id/lvArrivals"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</LinearLayout>
<LinearLayout
android:id="#+id/llFooter"
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"/>
<LinearLayout
android:id="#+id/footerLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:background="#drawable/top_bg" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:layout_marginTop="5dp"
android:src="#drawable/filter" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:layout_marginTop="5dp"
android:src="#drawable/sort" />
</LinearLayout>
</LinearLayout>
And this my Layout that i am putting in the ListView at RunTime
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/flightLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="5sp"
android:layout_marginRight="10sp"
android:layout_marginTop="5sp"
android:src="#drawable/spicejet" />
<TextView
android:id="#+id/flightCompanyName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/flightLogo"
android:text="Spice Jet" />
<TextView
android:id="#+id/flightNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/flightCompanyName"
android:text="9W-123" />
<TextView
android:id="#+id/flightTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/flightLogo"
android:gravity="center_vertical"
android:text="6:00 - 7:00" />
<TextView
android:id="#+id/flightStop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/flightTime"
android:layout_toRightOf="#+id/flightLogo"
android:text="1h 35m | Non Stop" />
<TextView
android:id="#+id/amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/flightStop"
android:layout_toRightOf="#+id/flightLogo"
android:text="Rs 20,000" />
</RelativeLayout>
I can't tell if this is your only problem yet but when you use layout_weight inside of a vertical LinearLayout then your layout_height should be 0dp.
Likewise if it is inside of a horizontal LinearLayout then the layout_width should be 0dp. Also, all of the layouts should have a weight if you are using it on one of thenm.
android:layout_below= in your third LinearLayout, I believe, is not a property of LinearLayout. That is a property of RelativeLayout.
My suggestion for this type of setup is to use RelativeLayout as the root layout. Then, for your header LinearLayout you can use android:layout_alignParentTop="true" and for your footer use android:layout_alignParentBottom="true" then stick your ListView in the middle with android:layout_below="#id/idOfHeaderLL"
<RelativeLayout
...>
<LinearLayout
android:id="#+id/headerLL"
android:layout_alignParentTop="true"
...>
<!-- add header veiws -->
</LinearLayout
<ListView
android:layout_below="#id/headerLL"
.../>
<LinearLayout
android:layout_alignParentBottom="true"
...>
<!-- add footer views -->
</LinearLayout>
</RelativeLayout>
I'm not going to rewrite the whole layout but that should give you an idea. The "..." is where you will put in your other properties such as height, width, etc...

Android scrollview is not scrolling

I have this layout with a scrollview inside:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#eeeeee">
<!-- HEADER -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#ffffff"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#868686"
android:orientation="vertical" >
</LinearLayout>
<RelativeLayout
android:id="#+id/parent_linear"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="#drawable/gradient_header" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:layout_marginBottom="#dimen/margin_normal"
android:layout_marginTop="#dimen/margin_small"
android:gravity="center_horizontal"
android:text="#string/proposed_plan_prompt"
android:textColor="#797A77"
android:textSize="15sp"
android:textStyle="bold" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#C7C7C7"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="#drawable/gradient_header_separator"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
<!-- BODY -->
<!-- Proposed plan (summary) -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin_normal"
android:layout_marginLeft="#dimen/margin_normal"
android:layout_marginRight="#dimen/margin_normal"
android:background="#drawable/border"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="#dimen/margin_small"
android:layout_marginRight="#dimen/margin_small"
android:orientation="vertical" >
<TextView
android:id="#+id/providerNameView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="ABCD"
android:textSize="25sp"
android:textStyle="bold" />
<TextView
android:id="#+id/planView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="1234"
android:textSize="12sp"
android:textColor="#737373"/>
</LinearLayout>
<View
android:id="#+id/separator"
android:layout_width="1dip"
android:layout_height="50dp"
android:layout_marginTop="#dimen/margin_small"
android:background="#drawable/gradient_vertical" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_alignParentRight="true"
android:layout_marginLeft="#dimen/margin_small"
android:layout_marginRight="#dimen/margin_small"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:layout_marginLeft="#dimen/margin_small"
android:layout_marginRight="#dimen/margin_small"
android:gravity="top"
android:orientation="horizontal" >
<TextView
android:id="#+id/priceView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="XY"
android:textSize="32sp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="+123"
android:textColor="#565756"
android:textSize="12sp" />
</LinearLayout>
<TextView
android:id="#+id/totPriceView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="(information)"
android:textColor="#737373"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/margin_normal"
android:layout_marginLeft="#dimen/margin_normal"
android:layout_marginRight="#dimen/margin_small"
android:layout_marginTop="#dimen/margin_normal"
android:orientation="vertical" >
<TextView
android:id="#+id/detailsTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Choose:"
android:textSize="12sp"
android:textStyle="bold" />
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="#+id/detailsTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin_small"
android:text="Best"
android:textColor="#737373"
android:textSize="12sp" />
</LinearLayout>
<TextView
android:id="#+id/detailsTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin_normal"
android:text="Details:"
android:textSize="12sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/margin_normal"
android:layout_marginLeft="#dimen/margin_normal"
android:layout_marginRight="#dimen/margin_small"
android:layout_marginTop="#dimen/margin_small"
android:background="#drawable/border"
android:orientation="vertical" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginLeft="90dp"
android:layout_marginRight="#dimen/margin_small"
android:background="#drawable/border"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/line1Layout"
android:layout_width="match_parent"
android:layout_height="30sp"
android:background="#ffffff"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:id="#+id/line1Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/font_normal" />
<TextView
android:id="#+id/line1Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/border_attribute"
android:textSize="#dimen/font_normal"
android:visibility="invisible" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/line2Layout"
android:layout_width="match_parent"
android:layout_height="30sp"
android:background="#EAEAEA"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:id="#+id/line2Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/font_normal" />
<TextView
android:id="#+id/line2Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/border_attribute"
android:textSize="#dimen/font_normal"
android:visibility="invisible" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/line3Layout"
android:layout_width="match_parent"
android:layout_height="30sp"
android:background="#ffffff"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:id="#+id/line3Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/font_normal" />
<TextView
android:id="#+id/line3Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/border_attribute"
android:textSize="#dimen/font_normal"
android:visibility="invisible" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/line4Layout"
android:layout_width="match_parent"
android:layout_height="30sp"
android:background="#EAEAEA"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:id="#+id/line4Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/font_normal" />
<TextView
android:id="#+id/line4Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/border_attribute"
android:textSize="#dimen/font_normal"
android:visibility="invisible" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/line5Layout"
android:layout_width="match_parent"
android:layout_height="30sp"
android:background="#ffffff"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:id="#+id/line5Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/font_normal" />
<TextView
android:id="#+id/line5Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/border_attribute"
android:textSize="#dimen/font_normal"
android:visibility="invisible" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/line6Layout"
android:layout_width="match_parent"
android:layout_height="30sp"
android:background="#EAEAEA"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:id="#+id/line6Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/font_normal" />
<TextView
android:id="#+id/line6Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/border_attribute"
android:textSize="#dimen/font_normal"
android:visibility="invisible" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
<ImageView
android:id="#+id/imageView1"
android:layout_width="100dp"
android:layout_height="140dp"
android:layout_gravity="left|center_vertical"
android:src="#drawable/robin4" />
</FrameLayout>
<Button
android:id="#+id/button_proposed_extras"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/margin_small"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="#dimen/margin_normal"
android:background="#drawable/button_transparent"
android:text="#string/extras_title"
android:textColor="#298A17"
android:textStyle="bold|italic"
android:visibility="invisible" />
</LinearLayout>
<Button
android:id="#+id/button_proposed_change"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin_normal"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="#drawable/button"
android:text="#string/proposition_change_title"
android:textColor="#ffffff"
android:textStyle="bold" />
<Button
android:id="#+id/button_proposed_no_change"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin_normal"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="#drawable/button_silver"
android:text="#string/proposition_no_change_title"
android:textColor="#298A17"
android:textStyle="bold" />
</LinearLayout>
The part with the scrollview displays at maximum size and is not scrolling.
The two buttons at the end are not displayed, they apparently don't fit in the screen.
I'd like to have the scroll working in order to have buttons appearing.
Why the scrolled layout is displayed at max size instead of being scrolled?
What would be the solution?
For making the buttons to appear in the screen you should have the buttons within the scroll too. Mostly, the screens that you design should have scrollview as the parent if the screen contains many components. Main ScrollView -> LinearLayout / RelativeLayout -> Add Components as needed. By doing so you should have be able to see the buttons also. In doing this way even if your layout changes to landscape the components wont get hidden and will be shown in the scroll. Hope you get my point and it helps you in solving your issue.
As far as the code above is concerned you will not be able to see the buttons as buttons are not within scrollview and hence the view below is hidden.
If doesn't scroll because its height is wrap_content.
As ChristopheCVB stated, your ScrollView needs to NOT be wrap_content. A ScrollView will only scroll if the content it contains is larger (read taller for a vertical ScrollView and wider for a horizontal ScrollView) that the ScrollView itself. If it is smaller, then it has no need to scroll.

Center Button horizontally doesn't work

hy!
I want to center my button horizontally, but this never work.
My Layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/minage"
android:layout_alignParentLeft="true"
android:padding="5dp" />
<TextView
android:id="#+id/ml_minage_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="5dp"/>
</RelativeLayout>
<SeekBar
android:id="#+id/ml_minage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:max="100"
style="#style/NFFSeek"
android:progressDrawable="#drawable/myseekbar"
android:layout_margin="5dp" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/maxage"
android:padding="5dp"/>
<TextView
android:id="#+id/ml_maxage_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="5dp" />
</RelativeLayout>
<SeekBar
android:id="#+id/ml_maxage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="#style/NFFSeek"
android:progressDrawable="#drawable/myseekbar"
android:layout_margin="5dp" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/distance"
android:padding="5dp" />
<TextView
android:id="#+id/ml_distance_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="5dp" />
</RelativeLayout>
<SeekBar
android:id="#+id/ml_distance"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="#style/NFFSeek"
android:progressDrawable="#drawable/myseekbar"
android:layout_margin="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/gender"
android:padding="5dp" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checkedButton="#drawable/rbon" >
<RadioButton
android:id="#+id/ml_female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:button="#drawable/rbselector"
android:checked="true"
android:drawablePadding="10dp"
android:text="#string/rb_female"
android:textColor="#000000"
android:paddingLeft="42dp" />
<RadioButton
android:id="#+id/ml_male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/rb_male"
android:button="#drawable/rbselector"
android:layout_margin="5dp"
android:textColor="#000000"
android:paddingLeft="42dp"
/>
</RadioGroup>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/ml_stbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:background="#drawable/custom_button"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:padding="10dp"
android:text="Flirt"
android:textColor="#ffffff"
android:textSize="12pt"
android:typeface="serif" />
</RelativeLayout>
</LinearLayout>
this xml doesn't fit the button in the middle please help.
The problem is that the RelativeLayout does not span the width of the page, it's width is wrap_content. The button is centered in the RelativeLayout, but that layout is only as wide as the button, and is mashed up against the left side of the screen.
Make the inner RelativeLayout's width as match_parent.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
...
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/ml_stbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:background="#drawable/custom_button"
android:layout_centerInParent="true"
android:gravity="center"
android:padding="10dp"
android:text="Flirt"
android:textColor="#ffffff"
android:textSize="12pt"
android:typeface="serif" />
</RelativeLayout>
This isn't speaking directly to your question, but your view hierarchy is too complicated. I suggest you replace all of the LinearLayout and RelativeLayout elements with a single RelativeLayout that spans the whole thing.

Categories

Resources