Align android layout with equal margin - android

I am adding a footer to my app which will contain three buttons with image. I want similar to below view. I have tried android:layout_gravity="right/left/center" but seems not working.
Below is my XML
<RelativeLayout 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"
>
<!-- Root element should wrap to parent size. -->
<!-- Your view xml codes. -->
<!--Bottom bar layout should be in root element. Parent should be Relative layout so that we can always align to parent bottom-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:weightSum="4">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="left"
android:orientation="vertical"
>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/brands"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="brands"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:layout_gravity="center_horizontal"
>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/stores"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="brands"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:layout_gravity="right"
>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/coupons"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="brands"
/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/brands"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="brands"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/shops"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="shops"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/coupons"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="coupons"
/>
</LinearLayout>
</LinearLayout>
Try Something like this,
LinearLayout(Horizontal)
- LinearLayout(Vertical)
- ImageView (for the image)
- Textview (for title)
- LinearLayout(Vertical)
- ImageView (for the image)
- Textview (for title)
- LinearLayout(Vertical)
- ImageView (for the image)
- Textview (for title)

Your parent LinearLayouthave android:weightSum="4" and your child LinearLayout all sum is 3.
so change your parent LinearLayout weightSum android:weightSum="4" to android:weightSum="3".
Update :
add this way
<RelativeLayout 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"
>
<!-- Root element should wrap to parent size. -->
<!-- Your view xml codes. -->
<!--Bottom bar layout should be in root element. Parent should be Relative layout so that we can always align to parent bottom-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:weightSum="3">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/brands"
android:layout_gravity="center_horizontal"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="brands"
android:layout_gravity="center_horizontal"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/stores"
android:layout_gravity="center_horizontal"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="brands"
android:layout_gravity="center_horizontal"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/coupons"
android:layout_gravity="center_horizontal"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="brands"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>

<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- Root element should wrap to parent size. -->
<!-- Your view xml codes. -->
<!--Bottom bar layout should be in root element. Parent should be Relative layout so that we can always align to parent bottom-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:weightSum="3">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/brands" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="brands" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/stores" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="brands" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/coupons" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="brands" />
</LinearLayout>
</LinearLayout>
Try this. I think it will solve your problem.

Please try this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:weightSum="3">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical"
android:padding="5dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/brands" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="brands" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical"
android:padding="5dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/stores" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stores" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical"
android:padding="5dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/coupons" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Coupons" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>

Give equal weight to layouts
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical"
android:layout_height="wrap_content">
<ImageView
android:layout_width="24dp"
android:src="#android:drawable/ic_menu_rotate"
android:layout_height="24dp" />
<TextView
android:layout_width="wrap_content"
android:text="#string/description"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical"
android:layout_height="wrap_content">
<ImageView
android:layout_width="24dp"
android:src="#android:drawable/ic_menu_rotate"
android:layout_height="24dp" />
<TextView
android:layout_width="wrap_content"
android:text="#string/description"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical"
android:layout_height="wrap_content">
<ImageView
android:layout_width="24dp"
android:src="#android:drawable/ic_menu_rotate"
android:layout_height="24dp" />
<TextView
android:layout_width="wrap_content"
android:text="#string/description"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>

change all inner layouts
android:layout_gravity="left"
android:layout_margin="10dp"//as required
and change
android:weightSum="3"
in parent layout

Related

Align element to the right in LinearLayout

I am trying to align the express badge to the right of the layout and I need the title to take as much width as possible. This is the code I have right now.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/listPreferredItemHeight"
android:orientation="horizontal"
android:padding="#dimen/margin_large">
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
tools:src="#drawable/ic_download" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical"
android:paddingStart="#dimen/margin_large"
android:paddingEnd="#dimen/margin_large">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="#+id/title"
style="#style/AppTheme.Text.Light.SemiDarker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Example of title" />
<com.client.presentation.components.ChipView
android:id="#+id/badge"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:id="#+id/subtitle"
style="#style/AppTheme.Text.Body1.Light"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Example of subtitle" />
</LinearLayout>
</LinearLayout>
The clue is to set weight to 1 in TextView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:minHeight="?attr/listPreferredItemHeight"
android:orientation="horizontal"
android:padding="#dimen/margin_large"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
tools:src="#drawable/ic_angry_android" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical"
android:paddingStart="32dp"
android:paddingEnd="32dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/title"
android:layout_weight="1"
style="#style/AppTheme.Text.Light.SemiDarker"
android:layout_width="0dp"
android:layout_height="wrap_content"
tools:text="Example of title" />
<....
</LinearLayout>
<TextView
android:id="#+id/subtitle"
style="#style/AppTheme.Text.Body1.Light"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Example of subtitle" />
</LinearLayout>
</LinearLayout>

Main Layout is set But Displaying in wrap content only

i create one layout parent layout all are match parent But still displaying wrap contain only. I tried all layout set match parent but it is not display in full width how can solve that type of issue.
<?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:background="#color/lightyellow"
android:orientation="vertical">
<include
android:id="#+id/rightLayout"
layout="#layout/header" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/padding_medium"
android:layout_marginRight="#dimen/padding_medium"
android:layout_marginTop="#dimen/padding_large"
android:dividerHeight="#dimen/padding_medium"
android:orientation="horizontal"
android:paddingBottom="#dimen/padding_medium"
android:paddingTop="#dimen/padding_medium">
<Spinner
android:id="#+id/spnSelectEventName"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.9"
android:background="#drawable/spinner_bg" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/image_bg" />
</LinearLayout>
Header Layout file is.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/GreenColor"
android:baselineAligned="false"
android:padding="#dimen/padding_medium"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/btn_header_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clickable="true"
android:gravity="center"
android:visibility="gone">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_sidemenu"
android:clickable="false"
android:duplicateParentState="true" />
</LinearLayout>
<TextView
android:id="#+id/txt_middle_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginBottom="#dimen/padding_small"
android:layout_marginTop="#dimen/padding_small"
android:gravity="center"
android:layout_weight="1"
android:text="Header Name"
android:textColor="#color/WhiteColor"
android:textSize="#dimen/TextSize_medium"
android:textStyle="bold"
android:visibility="visible" />
<LinearLayout
android:id="#+id/btn_header_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|right"
android:clickable="true"
android:gravity="center"
android:visibility="gone">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_search_home"
android:clickable="false"
android:duplicateParentState="true" />
</LinearLayout>
Make changes to your Layout as below. Remove unnecessary padding and margins from that Layout. And give some weight to ImageView as well so it will work properly.
<?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:background="#android:color/holo_blue_light"
android:orientation="vertical">
<include
android:id="#+id/rightLayout"
layout="#layout/header" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:dividerHeight="5dp"
android:orientation="horizontal"
android:weightSum="2">
<Spinner
android:id="#+id/spnSelectEventName"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.5" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_weight="0.5"
android:src="#mipmap/ic_launcher" />
</LinearLayout>
</LinearLayout>

Display two text field in vertically(one below the other in list view)

I want to display text field Duration below the text field Item.I am having the list view which is populated in different for even and odd rows. But the thing is I want the two text field in parallel to image I want to display vertically, but when I put the two text field in the Liner Vertical layout it shows error. How to display the two text field in vertical manner. Sorry if any mistake in my english. Thanks in advance.
Below is my code:
<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="horizontal" >
<ImageView
android:id="#+id/gender_image"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="39.5"
android:contentDescription="#string/app_name"
android:src="#drawable/male" />
<TextView
android:id="#+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="60"
android:gravity="center"
android:textColor="#android:color/holo_green_dark" />
<TextView
android:id="#+id/name1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="60"
android:gravity="center"
android:textColor="#android:color/holo_green_light" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/gender_image"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="39.5"
android:contentDescription="#string/app_name"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="60"
android:gravity="center"
android:textColor="#android:color/holo_green_dark" />
<TextView
android:id="#+id/name1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="60"
android:gravity="center"
android:textColor="#android:color/holo_green_light" />
</LinearLayout>
Try this!!!
It will give the view, what you are looking till.
Please check below my code here i manage your both different item view in single layout so you have just show/hide respective layout based on item :
<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:gravity="center">
<LinearLayout
android:id="#+id/male_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/gender_image_male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="#string/app_name"
android:src="#drawable/male" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/name_male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#android:color/holo_green_dark" />
<TextView
android:id="#+id/name1_male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#android:color/holo_green_light" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/female_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/gender_image_female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="#string/app_name"
android:src="#drawable/female" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/name_female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#android:color/holo_green_dark" />
<TextView
android:id="#+id/name1_female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#android:color/holo_green_light" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Note : android:layout_weight is used take rest of area.
use 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="horizontal" >
<ImageView
android:id="#+id/gender_image"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="39.5"
android:contentDescription="#string/app_name"
android:src="#drawable/male" />
<LinearLayout
android:layout_weight="60.5"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent">
<TextView
android:id="#+id/name"
android:text="asdasdas"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="60"
android:gravity="center"
android:textColor="#android:color/holo_green_dark" />
<TextView
android:id="#+id/name1"
android:text="asdasd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="60"
android:gravity="center"
android:textColor="#android:color/holo_green_light" />
</LinearLayout>
</LinearLayout>
<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="horizontal" >
<ImageView
android:id="#+id/gender_image"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="39.5"
android:contentDescription="#string/app_name"
android:src="#drawable/male" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="60"
android:gravity="center"
android:textColor="#android:color/holo_green_dark" />
<TextView
android:id="#+id/name1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="60"
android:gravity="center"
android:textColor="#android:color/holo_green_light" />
</LinearLayout>
</LinearLayout>
PS: put the weights and width accordingly... :)

How to set content in a Linear layout to the BOTTOM of the Screen in Android.?

See the following XML code
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<include layout="#layout/header" />
<TextView
android:layout_width="fill_parent"
android:layout_height="18dp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/header"
android:orientation="horizontal" >
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/calendar" />
<TextView
android:id="#+id/tvTitle"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:gravity="center"
android:text="#string/calendar"
android:textColor="#FFFFFFFF"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/myLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
<!-- <include layout="#layout/footer"/> -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#drawable/datename_bottom_bg"
android:orientation="horizontal">
<TextView
android:id="#+id/upgrade_4"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_weight="1"
android:drawableTop="#drawable/upgrade"
android:gravity="center"
android:text="#string/upgrade"
android:textSize="8sp" />
<TextView
android:id="#+id/panchang_4"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_weight="1"
android:drawableTop="#drawable/kalash_bottom"
android:gravity="center"
android:text="#string/panchang"
android:textSize="8sp" />
<TextView
android:id="#+id/time_range_4"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_weight="1"
android:drawableTop="#drawable/timer_bottom"
android:gravity="center"
android:text="#string/timespan"
android:textSize="8sp" />
<TextView
android:id="#+id/reminder_4"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_weight="1"
android:drawableTop="#drawable/reminder_bottom"
android:gravity="center"
android:text="#string/reminders"
android:textSize="8sp" />
<!--
<TextView android:id="#+id/calendar_4" android:layout_width="50dp" android:layout_height="50dp" android:drawableTop="#drawable/calendar_bottom"
android:text="#string/calendar" android:textSize="8sp" android:gravity="center" android:layout_weight="1"/>
-->
</LinearLayout >
</LinearLayout>
</ScrollView>
What this looks like is on the left and what I want it to look like is on the right, I also tried it by replacing LinearLayout to RelativeLaout but still not working. Please Help.!
You should use RelativeLayout, Look for example
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffff0000"
android:layout_above="#+id/bottom_panel">
</ScrollView>
<LinearLayout
android:id="#+id/bottom_panel"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Button 1"/>
<Button
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Button 2"/>
<Button
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Button 3"/>
<Button
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Button 4"/>
</LinearLayout>
</RelativeLayout>
This will give you something similar. Just place your widgets instead of my buttons.
why dont you just use relative layout as parent layout set the view as alignparentbottom= true.then if really need it you can put a linear layout in the remaining space
You can include your LinearLayout into a FrameLayout and select in your LinearLayout the attribute android:layout_gravity="bottom":
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom">
<!--Your LinearLayout content-->
</LinearLayout>
</FrameLayout>
Try relative layout inside which you can add linear layout.
set gravity:bottom to LinearLayout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:orientation="vertical" >
<include layout="#layout/header" />
<TextView
android:layout_width="fill_parent"
android:layout_height="18dp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/header"
android:orientation="horizontal" >
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/calendar" />
<TextView
android:id="#+id/tvTitle"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:gravity="center"
android:text="#string/calendar"
android:textColor="#FFFFFFFF"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/myLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
<!-- <include layout="#layout/footer"/> -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#drawable/datename_bottom_bg"
android:orientation="horizontal">
<TextView
android:id="#+id/upgrade_4"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_weight="1"
android:drawableTop="#drawable/upgrade"
android:gravity="center"
android:text="#string/upgrade"
android:textSize="8sp" />
<TextView
android:id="#+id/panchang_4"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_weight="1"
android:drawableTop="#drawable/kalash_bottom"
android:gravity="center"
android:text="#string/panchang"
android:textSize="8sp" />
<TextView
android:id="#+id/time_range_4"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_weight="1"
android:drawableTop="#drawable/timer_bottom"
android:gravity="center"
android:text="#string/timespan"
android:textSize="8sp" />
<TextView
android:id="#+id/reminder_4"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_weight="1"
android:drawableTop="#drawable/reminder_bottom"
android:gravity="center"
android:text="#string/reminders"
android:textSize="8sp" />
<!--
<TextView android:id="#+id/calendar_4" android:layout_width="50dp" android:layout_height="50dp" android:drawableTop="#drawable/calendar_bottom"
android:text="#string/calendar" android:textSize="8sp" android:gravity="center" android:layout_weight="1"/>
-->
</LinearLayout >
</LinearLayout>

Unwanted space between two layouts in android

Hi
I have designed a layout, i have attached a screen shot of it. I was getting an unwanted space between linear layout(tabsFragmentll) and grid view linear layout, so to remove the space i added a tag in linear layout grid view as android:layout_marginTop= "-10dp".
After adding the tag, it removed the space between the linear layout(tabsFragmentll) and grid view linear layout, but at the bottom of the screen i am getting an unwanted space which is shown at the bottom of the screen.
I am trying hard to remove the unwanted spaces, but am not able to do so. Please look in to it and give me your suggestions.
The following is my layout design code:
<LinearLayout
android:id="#+id/slide_show_content"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.7" >
<FrameLayout
android:id="#+id/slide_show_fragment_content"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<LinearLayout
android:id="#+id/tabsFragmentll"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.1" >
<fragment
android:name="com.beverly.fragments.TabsButtonFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_marginTop="-10dp"
android:layout_weight="1.15"
android:baselineAligned="false" >
<RelativeLayout
android:id="#+id/center_pane_rl"
android:layout_width="200dp"
android:layout_height="fill_parent" >
<FrameLayout
android:id="#+id/center_pane_frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ProgressBar
android:id="#+id/places_list_view_progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="gone" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<FrameLayout
android:id="#+id/tab_fragment_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</LinearLayout>
<TableRow
android:id="#+id/tableRowBtns"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.1"
android:background="#drawable/toolbar_background" >
<FrameLayout
android:id="#+id/checkinframe"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true" >
<ImageButton
android:id="#+id/checkInIB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="5dp"
android:background="#android:color/transparent"
android:src="#drawable/checkin" />
<TextView
android:id="#+id/checkInTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="12dp"
android:text="#string/checkin"
android:textSize="14sp" />
</FrameLayout>
<FrameLayout
android:id="#+id/cameraframe"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true" >
<ImageButton
android:id="#+id/cameraIB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="5dp"
android:background="#android:color/transparent"
android:src="#drawable/camera" />
<TextView
android:id="#+id/cameraTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="12dp"
android:text="#string/camera"
android:textSize="14sp" />
</FrameLayout>
<FrameLayout
android:id="#+id/photosframe"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true" >
<ImageButton
android:id="#+id/photosIB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="5dp"
android:background="#android:color/transparent"
android:src="#drawable/photos" />
<TextView
android:id="#+id/photosTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="12dp"
android:text="#string/photos"
android:textSize="14sp" />
</FrameLayout>
<FrameLayout
android:id="#+id/termsframe"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true" >
<ImageButton
android:id="#+id/termsIB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="5dp"
android:background="#android:color/transparent"
android:src="#drawable/terms" />
<TextView
android:id="#+id/termsTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="12dp"
android:text="#string/terms"
android:textSize="14sp" />
</FrameLayout>
</TableRow>

Categories

Resources