How to add footer to the layout? - android

This is my layout.xml in which i want to add a fixed footer at the bottom of listview.Also, it's not possible for me to change my current layout.This layout contains an action bar at the top.The very first relative layout contains all layout including action bar relative layout to below of which i have a frame layout containing listview.I want this listview to have a footer fixed at the bottom containing some image buttons.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<!-- This acts as Actionbar -->
<RelativeLayout
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:paddingRight="10dp"
android:orientation="horizontal"
android:background="#drawable/action_bar_background_strip" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:clickable="true"
android:onClick="toggleMenu"
android:contentDescription="#null"
android:src="#drawable/drawer_toggle_button" />
<View
android:id="#+id/View1"
android:layout_width="1dp"
android:layout_height="fill_parent"
android:layout_marginLeft="20dp"
android:layout_toRightOf="#+id/imageView1"
android:background="#ffffff" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_toRightOf="#+id/View1"
android:layout_marginTop="8dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="115dp"
android:text="Listview"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff"
android:textStyle="bold" />
<View
android:id="#+id/View2"
android:layout_width="1dp"
android:layout_height="fill_parent"
android:layout_toRightOf="#+id/textView1"
android:background="#ffffff" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:contentDescription="#null"
android:src="#drawable/icon" />
</RelativeLayout>
<FrameLayout
android:layout_below="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="#+id/listView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:choiceMode="multipleChoice" >
</ListView>
</FrameLayout>

For example you can: create new layout for your footer and place it at bottom of its parent and make your FrameLayout to be placet above your footer
Use android:layout_above and android:layout_alignParentBottom properties of your layouts...
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- This acts as Actionbar -->
<RelativeLayout
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:paddingRight="10dp"
android:orientation="horizontal"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:clickable="true"
android:onClick="toggleMenu"
android:contentDescription="#null" />
<View
android:id="#+id/View1"
android:layout_width="1dp"
android:layout_height="fill_parent"
android:layout_marginLeft="20dp"
android:layout_toRightOf="#+id/imageView1"
android:background="#ffffff" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_toRightOf="#+id/View1"
android:layout_marginTop="8dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="115dp"
android:text="Listview"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff"
android:textStyle="bold" />
<View
android:id="#+id/View2"
android:layout_width="1dp"
android:layout_height="fill_parent"
android:layout_toRightOf="#+id/textView1"
android:background="#ffffff" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:contentDescription="#null" />
</RelativeLayout>
<FrameLayout
android:layout_below="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/linearLayout">
<ListView
android:id="#+id/listView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:choiceMode="multipleChoice">
</ListView>
</FrameLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#+id/linearLayout">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button" />
</LinearLayout>

Make a footer.xml like below:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="#5E616B"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:weightSum="1" >
<ImageButton
android:id="#+id/btn_one"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="15dp"
android:layout_marginTop="2dp"
android:layout_weight=".2"
android:background="#drawable/footer_button_pressed"
android:src="#drawable/pingicon" />
<ImageButton
android:id="#+id/btn_two"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="15dp"
android:layout_marginTop="2dp"
android:layout_weight=".2"
android:background="#drawable/footer_button_pressed"
android:src="#drawable/profile" />
<ImageButton
android:id="#+id/btn_three"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="15dp"
android:layout_marginTop="2dp"
android:layout_weight=".2"
android:background="#drawable/footer_button_pressed"
android:src="#drawable/mycircle" />
<ImageButton
android:id="#+id/btn_four"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="15dp"
android:layout_marginTop="2dp"
android:layout_weight=".2"
android:background="#drawable/footer_button_pressed"
android:src="#drawable/sendping" />
<ImageButton
android:id="#+id/btn_five"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="15dp"
android:layout_marginTop="2dp"
android:layout_weight=".2"
android:background="#drawable/footer_button_pressed"
android:src="#drawable/settings" />
</LinearLayout>
The idea here is simple.Take a linear layout with weightsum 1 and divide that weight to their childs.Here I have taken 5 imagebuttons and distributed .2 weight to each of them.Dont forget to set the layout orientation to vertical.
Then include the footer in your layout like:
<include
android:id="#+id/footer"
layout="#layout/footer" />
Then design your SCROLLVIEW as:
<FrameLayout
android:layout_below="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/footer"
android:layout_below="#+id/header"(IF ANY) >
<ListView
android:id="#+id/listView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:choiceMode="multipleChoice" >
</ListView>
</FrameLayout>

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/linearLayout1" >
</ListView>
<!-- Footer linear layout -->
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="55dp"
android:weightSum="5"
android:layout_marginBottom="-5dp"
android:orientation="horizontal"
android:layout_alignParentBottom="true" >
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginLeft="-4.5dp"
android:layout_marginRight="-4dp"
android:layout_marginTop="-5dp"
android:contentDescription="#null"
android:src="#drawable/filing_button_icon" />
<ImageButton
android:id="#+id/imageButton2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginLeft="-4.5dp"
android:layout_marginRight="-4.5dp"
android:layout_marginTop="-5dp"
android:contentDescription="#null"
android:src="#drawable/delete_icon" />
<ImageButton
android:id="#+id/imageButton3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginLeft="-4dp"
android:layout_marginRight="-4.5dp"
android:layout_marginTop="-5dp"
android:contentDescription="#null"
android:src="#drawable/reply_all_icon" />
<ImageButton
android:id="#+id/imageButton4"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginLeft="-4dp"
android:layout_marginRight="-4.5dp"
android:layout_marginTop="-5dp"
android:contentDescription="#null"
android:src="#drawable/reply_icon" />
<ImageButton
android:id="#+id/imageButton5"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginLeft="-4dp"
android:layout_marginRight="-4.5dp"
android:layout_marginTop="-5dp"
android:contentDescription="#null"
android:src="#drawable/forward_icon" />
</LinearLayout>
</RelativeLayout>

Related

Add scrollView and highlight on a Linear Layout in Android

I have Linearlayout that have have multiple linear layouts in which one of the main layout have a LinearLayout and Listview. LinearLayout contains multiple ImageView and TextView now I want to add ScrollView on this LinearLayout. But if I am adding the ScrollView my ListView got hidden and onClick of the ImageView I want to highlight that LinearLayout.
My XML is :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id ="#+id/mainFilterLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/companyLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".1"
android:layout_gravity="left"
android:adjustViewBounds="true"
android:background="#mipmap/ic_launcher" />
<View
android:clickable="true"
android:layout_gravity="center"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<Button
android:id="#+id/btnClear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:gravity="right|center"
android:text="Clear" />
<Button
android:id="#+id/btnApply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:gravity="right|center"
android:text="Apply" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
//**I want to add scroll view on this linear layout**
<LinearLayout
android:id="#+id/categoryLayout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="vertical">
<LinearLayout
android:id="#+id/brandLayout"
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="vertical">
//**Here on click of imageviwew i want set as selected for this linear layout**
<ImageView
android:id="#+id/mobbrand"
android:layout_width="90dp"
android:layout_height="50dp"
android:background="#mipmap/ic_launcher"
android:layout_gravity="center" />
<TextView
android:id="#+id/txtBrand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Brand" />
</LinearLayout>
<LinearLayout
android:id="#+id/colorLayout"
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="vertical">
<ImageView
android:id="#+id/mobColor"
android:layout_width="90dp"
android:layout_height="50dp"
android:background="#mipmap/ic_launcher"
android:layout_gravity="center" />
<TextView
android:id="#+id/txtColor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="COLOUR" />
</LinearLayout>
<LinearLayout
android:id="#+id/sizeLayout"
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="vertical">
<ImageView
android:id="#+id/mobSize"
android:layout_width="90dp"
android:layout_height="50dp"
android:background="#mipmap/ic_launcher"
android:layout_gravity="center" />
<TextView
android:id="#+id/txtSize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Size" />
</LinearLayout>
<LinearLayout
android:id="#+id/offerLayout"
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="vertical">
<ImageView
android:id="#+id/mobOffers"
android:layout_width="90dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:background="#mipmap/ic_launcher" />
<TextView
android:id="#+id/txtPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Price" />
</LinearLayout>
<LinearLayout
android:id="#+id/othersLayout"
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="vertical">
<ImageView
android:id="#+id/mobother"
android:layout_width="90dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:background="#mipmap/ic_launcher" />
<TextView
android:id="#+id/txtOther"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="OTHER" />
</LinearLayout>
</LinearLayout>
<ListView
android:id="#+id/subCategory"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5"
android:cacheColorHint="#android:color/transparent"
android:divider="#fff"
android:dividerHeight="1dp"
android:fadingEdge="none">
</ListView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
I hope this will work for u :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id ="#+id/mainFilterLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/companyLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".1"
android:layout_gravity="left"
android:adjustViewBounds="true"
android:background="#mipmap/ic_launcher" />
<View
android:clickable="true"
android:layout_gravity="center"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<Button
android:id="#+id/btnClear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:gravity="right|center"
android:text="Clear" />
<Button
android:id="#+id/btnApply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:gravity="right|center"
android:text="Apply" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="vertical">
<LinearLayout
android:id="#+id/brandLayout"
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="vertical">
<ImageView
android:id="#+id/mobbrand"
android:layout_width="90dp"
android:layout_height="50dp"
android:background="#mipmap/ic_launcher"
android:layout_gravity="center" />
<TextView
android:id="#+id/txtBrand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Brand" />
</LinearLayout>
<LinearLayout
android:id="#+id/colorLayout"
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="vertical">
<ImageView
android:id="#+id/mobColor"
android:layout_width="90dp"
android:layout_height="50dp"
android:background="#mipmap/ic_launcher"
android:layout_gravity="center" />
<TextView
android:id="#+id/txtColor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="COLOUR" />
</LinearLayout>
<LinearLayout
android:id="#+id/sizeLayout"
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="vertical">
<ImageView
android:id="#+id/mobSize"
android:layout_width="90dp"
android:layout_height="50dp"
android:background="#mipmap/ic_launcher"
android:layout_gravity="center" />
<TextView
android:id="#+id/txtSize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Size" />
</LinearLayout>
<LinearLayout
android:id="#+id/offerLayout"
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="vertical">
<ImageView
android:id="#+id/mobOffers"
android:layout_width="90dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:background="#mipmap/ic_launcher" />
<TextView
android:id="#+id/txtPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Price" />
</LinearLayout>
<LinearLayout
android:id="#+id/othersLayout"
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="vertical">
<ImageView
android:id="#+id/mobother"
android:layout_width="90dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:background="#mipmap/ic_launcher" />
<TextView
android:id="#+id/txtOther"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="OTHER" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<ListView
android:id="#+id/subCategory"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5"
android:cacheColorHint="#android:color/transparent"
android:divider="#fff"
android:dividerHeight="1dp"
android:fadingEdge="none">
</ListView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Simply do one thing cut the amount of code that you want in scrollview.... Now add scrollview in place of the code that u just "cut" ... now scrollview also have a child layout as linear layout.... in that linear layout make height to be wrap_content..... next place your code inside that linear layout... ListView outside the scrollayout...
[code]--------- Ctrl+X
replace with
<ScrollView>
<LinearLayout>
[code]-------- Ctrl+V
enter code here
</LinearLayout>
</ScrollView>
<ListView> -------- here add listview

How to show arrow images in center?

In my app I have one layout to show text on top, image in center and then text in bottom. But now I want to try add Images of left arrow on left side and right arrow on right side in center of the image layout. Because I am using swipe in activity.
Following is my xml code and what I have tried. I want to use weight if it is possible.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#drawable/light" >
<LinearLayout
android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textSize="#dimen/txt"
android:textColor="#FFFFFF"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:orientation="vertical" >
/////////////////////////I have tried this
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="1">
<ImageView android:layout_width="35dp"
android:layout_height="45dp"
android:layout_gravity="center|left"
android:background="#drawable/left"/>
<ImageView android:layout_width="35dp"
android:layout_height="45dp"
android:layout_gravity="center|right"
android:background="#drawable/right"/>
</LinearLayout>
///////////////////////////////////////
</LinearLayout>
<View
android:id="#+id/top_space"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:background="#null"
android:gravity="center"
android:layout_weight=".5" />
<LinearLayout
android:id="#+id/layout3"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2.5"
android:orientation="vertical" >
<com.info.abc.TextViewEx
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:scrollbars="vertical"
android:textColor="#FFFFFF"
android:textSize="#dimen/betxt"/>
</LinearLayout>
</LinearLayout>
Try this..
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="1">
<ImageView
android:layout_width="0dp"
android:layout_height="45dp"
android:layout_weight="0.2"
android:layout_gravity="center"
android:src="#drawable/left"/>
<ImageView android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:layout_gravity="center"
android:src="#drawable/yourimage"/>
<ImageView
android:layout_width="0dp"
android:layout_height="45dp"
android:layout_weight="0.2"
android:layout_gravity="center"
android:src="#drawable/right"/>
</LinearLayout>
OR
<LinearLayout
android:id="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
<ImageView
android:layout_width="35dp"
android:layout_height="45dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:src="#drawable/left" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/yourimage" />
<ImageView
android:layout_width="35dp"
android:layout_height="45dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:src="#drawable/right" />
</RelativeLayout>
</LinearLayout>
I would suggest using a RelativeLayout for your need.
Try this with Using RelativeLayout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="5"
android:orientation="horizontal" >
<ImageView
android:layout_width="35dp"
android:layout_height="45dp"
android:layout_centerVertical="true"
android:background="#drawable/ic_launcher" />
<ImageView
android:layout_width="35dp"
android:layout_height="45dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="#drawable/ic_launcher" />
</RelativeLayout>
I have changed your LinearLayout with the RelativeLayout and made its gravity to center and set the images to left and right and it done.
Just change your layout android:id="#+id/layout2" with RelativeLayout as below:
<LinearLayout
android:id="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:gravity="center" >
<ImageView
android:layout_width="35dp"
android:layout_height="45dp"
android:layout_gravity="center"
android:layout_alignParentLeft="true"
android:background="#drawable/left" />
<ImageView
android:layout_width="35dp"
android:layout_height="45dp"
android:layout_gravity="center"
android:layout_alignParentRight="true"
android:background="#drawable/right" />
</RelativeLayout>
</LinearLayout>
You can use Relative layout like:-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="#+id/yourTextItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="60dp"
android:layout_centerInParent="true"
android:layout_marginBottom="20dp" >
<Button
android:id="#+id/left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
>
</Button>
<Button
android:id="#+id/right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
>
</Button>
</RelativeLayout>
</RelativeLayout>
layout design using weight
<LinearLayout
android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="gaesh"
android:textColor="#4FFFFF"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="8"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:layout_gravity="center|left"
android:src="#drawable/yout image "
android:background="#123456" />
<ImageView
android:layout_width="0dp"
android:layout_weight="8"
android:layout_height="match_parent"
android:layout_gravity="center|right"
android:src="#drawable/yout image "
android:background="#334343" />
<ImageView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:layout_gravity="center|right"
android:src="#drawable/yout image "
android:background="#654321" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/layout3"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >
<com.info.abc.TextViewEx
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textColor="#FFFFFF"
android:textSize="14sp" />
</LinearLayout>

Implementing this Layout

I want to achieve this layout:
The nearest that i have been able to come to is this:
The layout so far is this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:baselineAligned="true"
android:orientation="vertical"
android:weightSum="4" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:paddingBottom="8dip" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#null"
android:scaleType="fitCenter"
android:src="#drawable/myimage" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:paddingBottom="8dip"
>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#null"
android:scaleType="fitCenter"
android:src="#drawable/myimage"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#null"
android:scaleType="fitCenter"
android:src="#drawable/myimage" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#null"
android:scaleType="fitCenter"
android:src="#drawable/myimage" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:paddingBottom="8dip" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#null"
android:scaleType="fitCenter"
android:src="#drawable/myimage" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#null"
android:scaleType="fitCenter"
android:src="#drawable/myimage" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#null"
android:scaleType="fitCenter"
android:src="#drawable/myimage" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:paddingBottom="8dip" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#null"
android:scaleType="fitCenter"
android:src="#drawable/myimage" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#null"
android:scaleType="fitCenter"
android:src="#drawable/myimage" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#null"
android:scaleType="fitCenter"
android:src="#drawable/myimage" />
</LinearLayout>
</LinearLayout>
How to design the above layout ?
create three linearlayouts with orientation set to vertical and equal layout weights. the child views of each linear layouts must also have equal layoutweights. set gravity of the first and third linearlayouts to be center_vertical.
This layout actually works as per your expectations:
<?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"
>
<!-- Center layout -->
<LinearLayout
android:id="#+id/llCenter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_centerInParent="true"
android:paddingBottom="8dp"
android:orientation="vertical"
>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scaleType="fitCenter"
android:src="#drawable/ic_launcher"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scaleType="fitCenter"
android:src="#drawable/ic_launcher"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scaleType="fitCenter"
android:src="#drawable/ic_launcher"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scaleType="fitCenter"
android:src="#drawable/ic_launcher"
/>
</LinearLayout>
<!-- Left layout -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#id/llCenter"
android:paddingBottom="8dp"
android:orientation="vertical"
>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scaleType="fitCenter"
android:src="#drawable/ic_launcher"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scaleType="fitCenter"
android:src="#drawable/ic_launcher"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scaleType="fitCenter"
android:src="#drawable/ic_launcher"
/>
</LinearLayout>
<!-- Right layout -->
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/llCenter"
android:paddingBottom="8dp"
android:orientation="vertical"
>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scaleType="fitCenter"
android:src="#drawable/ic_launcher"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scaleType="fitCenter"
android:src="#drawable/ic_launcher"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scaleType="fitCenter"
android:src="#drawable/ic_launcher"
/>
</LinearLayout>
</RelativeLayout>
Result:
Why don't you leave the unnecessary layouts...??
And use the following...
<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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="100dp"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="100dp"
android:layout_height="55dp"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="100dp"
android:layout_height="75dp"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="100dp"
android:layout_height="95dp"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="100dp"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="100dp"
android:layout_height="55dp"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="100dp"
android:layout_height="75dp"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="100dp"
android:layout_height="95dp"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="100dp"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="100dp"
android:layout_height="55dp"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="100dp"
android:layout_height="75dp"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="100dp"
android:layout_height="95dp"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
</LinearLayout>
What about extending ViewGroup?
If you check the documentation there is an example of how you should create your custom children container.
Basically in your layout you have the following rules:
The gravity of the children is centered vertically
For the odd columns the middle element overlap with the line that goes from left to right centered vertically
For the even columns you have got n/2 elements over that line and the remaining ones (n/2) below the same one
If you are able to do that implementing a custom layout, at the cost of more time for development, you'll have a better result and it doesn't matter the number of elements that you want to add... you'll have a layout that can manage different situations.
I suggest you to have a look at custom attributes as well, in order to allow the integration of the attributes that you'll need directly into the XML declaration.

Embedded views layout_weight

In my app I have an actvity with following layot. And I have proplem with layout_weight. When I use weights with views that embedded in container, that also have weight parametr,wieghts of this doesn't work. Is it posible use embedded view weight in Android?
<?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:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="10" >
<RelativeLayout
android:id="#+id/headerLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="top"
android:layout_weight="1"
android:background="#color/header_color"
android:orientation="horizontal" >
<View
android:id="#+id/main_backView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#null" />
<ImageButton
android:id="#+id/menuBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/appNameText"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/appNameText"
android:layout_centerVertical="true"
android:layout_gravity="left"
android:layout_marginLeft="30px"
android:background="#null"
android:scaleType="fitCenter"
android:src="#drawable/menu"
tools:ignore="ContentDescription" />
<TextView
android:id="#+id/mapClickText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="30px"
android:text="#string/map_text"
android:textColor="#android:color/white"
android:textSize="21sp" />
<TextView
android:id="#+id/appNameText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/app_name"
android:textColor="#android:color/white"
android:textSize="21sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="8" >
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="10" >
<RelativeLayout
android:id="#+id/imagePager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="top"
android:layout_weight="4"
android:background="#android:color/white" >
<mobi.esys.custom_components.AutoSwitchPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.viewpagerindicator.CirclePageIndicator
android:id="#+id/indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20px"
android:padding="2px" />
<TextView
android:id="#+id/bannerText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textColor="#android:color/white"
android:textSize="21sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/suggestIndicator"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="1"
android:background="#color/suggestions_indicator_color" >
<TextView
android:id="#+id/suggAmount"
android:layout_width="60px"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="30px"
android:background="#drawable/circle"
android:gravity="center"
android:textColor="#color/suggestions_indicator_color"
android:textSize="21sp" />
<TextView
android:id="#+id/suggText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="10px"
android:layout_marginTop="6px"
android:layout_toRightOf="#+id/suggAmount"
android:text="#string/sugg"
android:textColor="#android:color/white"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/suggVisitText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/suggAmount"
android:layout_marginLeft="10px"
android:layout_toRightOf="#+id/suggAmount"
android:textColor="#android:color/white"
android:textSize="12sp" />
<ImageButton
android:id="#+id/arrowBtn"
android:layout_width="30px"
android:layout_height="40px"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="30px"
android:background="#null"
android:scaleType="fitXY"
android:src="#drawable/arrow" />
</RelativeLayout>
<GridLayout
android:id="#+id/whereTab"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:columnCount="2" >
</GridLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
<ImageView
android:id="#+id/logoImage"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="bottom"
android:layout_weight="1"
android:scaleType="fitXY"
android:src="#drawable/logo"
tools:ignore="ContentDescription" />
</LinearLayout>
The weight mechanism distributes any remaining space in the parent linear layout after the first layout pass. A wrap_content layout doesn't have any remaining space. For what it's worth, a ScrollView doesn't work with match_parent height either.

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