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>
Related
I want to create an activity that contains 5 "FrameLayout" like the picture below.
3 equal FrameLayout in the first row and 2 FrameLayout in the second row.
I did it using Linear layouts but I got a warning that nested weights are bad. So is there an other way to make it.
Fragments should be streched on the screen without using values like (100dp).
you cal also use the two table layout..
like
<TableLayout android:weight='1'>
<TableRow>
<Linear>
<FrameLayout /> <FrameLayout /> <FrameLayout />
</Linear>
</TableRow>
</TableLayout>
<TableLayout android:weight='1'>
<TableRow>
<Linear>
<FrameLayout /> <FrameLayout/>
</Linear>
</TableRow>
</TableLayout>
its rough layout . i hope you got the idea.
Try 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"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<FrameLayout
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:background="#00bbff" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="1" />
</FrameLayout>
<FrameLayout
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:background="#bb00ff" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="2" />
</FrameLayout>
<FrameLayout
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:background="#00ff00" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="3" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<FrameLayout
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:background="#bbff00">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="4" />
</FrameLayout>
<FrameLayout
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:background="#ffbb00" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="5" />
</FrameLayout>
</LinearLayout>
</LinearLayout>
Try this::Hope its useful for you.
<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"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp" >
<FrameLayout
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:background="#00bbff"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="1" />
</FrameLayout>
<View android:layout_width="10dp"
android:layout_height="10dp"
/>
<FrameLayout
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:background="#bb00ff"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="2"
/>
</FrameLayout>
<View android:layout_width="10dp"
android:layout_height="10dp"
/>
<FrameLayout
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:background="#00ff00"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="3" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp">
<FrameLayout
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:background="#bbff00" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="4" />
</FrameLayout>
<View android:layout_width="10dp"
android:layout_height="10dp"
/>
<FrameLayout
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:background="#ffbb00" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="5" />
</FrameLayout>
</LinearLayout>
</LinearLayout>
see image below ![image][1]
See This code
<?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="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#FFFFFF"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="2dp"
android:background="#FFFFFF"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="2dp"
android:background="#FFFFFF"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="1"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="100dp"
android:layout_marginTop="2dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="150dp"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"/>
</LinearLayout>
<LinearLayout
android:layout_width="150dp"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:gravity="center"
android:layout_marginLeft="1dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4" />
</LinearLayout>
</LinearLayout>
I currently have code that allows me to divide the screen into four equal parts, with an image button in each part. However, the code uses linear layouts which brings up the suggestion "nested weights are bad for performance". How can I make my layout using relative layouts?
Below is the code, and here is a picture of the intended format
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:orientation="horizontal"
android:background="#ff191919">
<ToggleButton
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff414141"
android:layout_weight="1.0"
android:text="Plane"
android:layout_margin="5dp"
android:textSize="20sp"
android:onClick="airplaneClicked"/>
<ImageButton
android:id="#+id/button2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff414141"
android:layout_weight="1.0"
android:layout_margin="5dp"
android:scaleType="fitCenter"
android:src="#drawable/ic_brightness"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:orientation="horizontal"
android:background="#ff191919">01
<ImageButton
android:id="#+id/button3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff414141"
android:layout_weight="1.0"
android:layout_margin="5dp"
android:scaleType="fitCenter"
android:src="#drawable/ic_sound" />
<ImageButton
android:id="#+id/settingsbutton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff414141"
android:layout_weight="1.0"
android:layout_margin="5dp"
android:scaleType="fitCenter"
android:src="#drawable/settings2"/>
</LinearLayout>
</LinearLayout>
Using below xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:background="#242425"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textColor="#d5d5d5" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:background="#d5d5d5"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:background="#d5d5d5"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:background="#242425"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textColor="#d5d5d5" />
</LinearLayout>
</LinearLayout>
Try this code for your RelativeLayout.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/r1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="#+id/r3"
android:layout_width="match_parent"
android:layout_height="225dp"
android:layout_marginBottom="10dp"
android:layout_alignParentTop="true" >
<ImageButton
android:id="#+id/i1"
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#drawable/ic_launcher" />
<ImageButton
android:id="#+id/i2"
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#drawable/ic_launcher" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/r2"
android:layout_width="match_parent"
android:layout_height="225dp"
android:layout_alignParentBottom="true"
android:layout_below="#+id/r3" >
<ImageButton
android:id="#+id/i3"
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#drawable/ic_launcher" />
<ImageButton
android:id="#+id/i4"
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#drawable/ic_launcher" />
</RelativeLayout>
</RelativeLayout>
Try this
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0">
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/button2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/holo_green_light"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:orientation="horizontal" >
<Button
android:id="#+id/button3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/holo_blue_light"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/button4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/holo_red_light"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
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>
I want to show four images as shown in given imaages . each image must be equally far apart from others I have tried a LinearLayout and use it weight property but all in sane.
I have eight icons, four for selected state and four for unselected state. I have tried many ways,
Thanks in Advance.
Image Icons are ..
xml
<?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"
android:background="#drawable/bg" >
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/bottom" />
<LinearLayout
android:id="#+id/bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/article_icn"
android:padding="10dp"
android:layout_margin="10dp"
android:scaleType="center" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/forum_icn"
android:padding="10dp"
android:layout_margin="10dp"
android:scaleType="fitXY" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/profile_icn"
android:padding="10dp"
android:layout_margin="10dp"
android:scaleType="fitXY" />
</LinearLayout>
</RelativeLayout>
I tried your code and modified a bit:
<?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" >
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/bottom" />
<LinearLayout
android:id="#+id/bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:weightSum="3" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#drawable/icon"
android:padding="10dp"
android:scaleType="center" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#drawable/icon"
android:padding="10dp"
android:scaleType="fitXY" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#drawable/icon"
android:padding="10dp"
android:scaleType="fitXY" />
</LinearLayout>
</RelativeLayout>
Assigning android:weightSum="3" to container and weight 1 to all images works fine:
Output:
Check this layout, works exactly as you want. Just replace the image icons and background.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:background="#517398" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center" >
<ImageButton
android:id="#+id/image_agenda"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center" >
<ImageButton
android:id="#+id/image_month"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center" >
<ImageButton
android:id="#+id/image_month"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center" >
<ImageButton
android:id="#+id/image_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
OUTPUT
You can use weight attrib:
<?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="wrap_content"
android:background="#000000"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:src="#android:drawable/sym_action_chat" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:src="#android:drawable/sym_action_chat" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:src="#android:drawable/sym_action_chat" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:src="#android:drawable/sym_action_chat" />
</LinearLayout>
output is like this:
Try this..
<?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" >
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/bottom" />
<LinearLayout
android:id="#+id/bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/ic_launcher"
android:padding="10dp"
android:scaleType="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Textview" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/ic_launcher"
android:padding="10dp"
android:scaleType="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Textview" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/ic_launcher"
android:padding="10dp"
android:scaleType="fitXY" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Textview" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/ic_launcher"
android:padding="10dp"
android:scaleType="fitXY" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Textview" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Screen
I'm writing a catalog app for Android tablet, which displays 6 item per page: 3 items for each row.
Each item is composed by an image (200x300) and a text.
Designing with android xml layout editor in Eclipse everything seems fine, because I'm using a default image for each item and a dummy fixed text: each item is horizontally perfectly equidistant there.
When I run on tablet, each item is overwritten with an image taken from filesystem (200x300 again) and the text (variable length) is taken from database.
The problem is taht after the 6 elements are populated with my custom data, the layout seems disaligned, as you can see from this screenshot:
Probably (but I'm not sure) the problem is caused by the long text.
Is there a way (if the problem is the text) to force the layout to remain fixed? (Or make the font small dinamically (or trunc the text, I don't care))
This is the layout I'm using:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RootView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/white"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/filaTop"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_margin="15dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:id="#+id/ivBottle1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="#drawable/bottle_trans" />
<TextView
android:id="#+id/tvBottle1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top|center"
android:text="vino"
android:textAlignment="center"
android:textSize="22sp" >
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:id="#+id/ivBottle2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="#drawable/bottle_trans" />
<TextView
android:id="#+id/tvBottle2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top|center"
android:text="vino"
android:textAlignment="center"
android:textSize="22sp" >
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:id="#+id/ivBottle3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="#drawable/bottle_trans" />
<TextView
android:id="#+id/tvBottle3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top|center"
android:text="vino"
android:textAlignment="center"
android:textSize="22sp" >
</TextView>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/filaBottom"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_margin="15dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:id="#+id/ivBottle4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="#drawable/bottle_trans" />
<TextView
android:id="#+id/tvBottle4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top|center"
android:text="vino"
android:textAlignment="center"
android:textSize="22sp" >
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:id="#+id/ivBottle5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="#drawable/bottle_trans" />
<TextView
android:id="#+id/tvBottle5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top|center"
android:text="vino"
android:textAlignment="center"
android:textSize="22sp" >
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:id="#+id/ivBottle6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="#drawable/bottle_trans" />
<TextView
android:id="#+id/tvBottle6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top|center"
android:text="vino"
android:textAlignment="center"
android:textSize="22sp" >
</TextView>
</LinearLayout>
</LinearLayout>
Thanks in advance.
EDIT (SOLVED): putting android:layout_width="0dip" in each linear layout, solved the problem as Dale Wilson suggested, like this:
<LinearLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
When you have layout_weight, start the views at 0px. The layout_weight will grow them all to the same size. If you say wrap_content then they start at different sizes, grow the same amounts, so they end up with different sizes.
Update your layout like below
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/RootView">
<LinearLayout android:layout_height="0dp"
android:layout_weight="1"
android:layout_width="match_parent"
android:id="#+id/filaTop">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ff00ff"
android:orientation="vertical" >
<ImageView
android:id="#+id/ivBottle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:background="#drawable/ic_launcher"
android:src="#drawable/bottle_trans" />
<TextView
android:id="#+id/tvBottle1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="top|center"
android:text="vino"
android:textAlignment="center"
android:textSize="22sp" >
</TextView>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:layout_centerInParent="true"
android:id="#+id/ivBottle2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_launcher"
android:layout_gravity="center"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="#drawable/bottle_trans" />
<TextView
android:layout_alignParentBottom="true"
android:id="#+id/tvBottle2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top|center"
android:text="vino"
android:textAlignment="center"
android:textSize="22sp" >
</TextView>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#0000ff"
android:orientation="vertical" >
<ImageView
android:layout_centerInParent="true"
android:id="#+id/ivBottle3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/ic_launcher"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="#drawable/bottle_trans" />
<TextView
android:layout_alignParentBottom="true"
android:id="#+id/tvBottle3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top|center"
android:text="vino"
android:textAlignment="center"
android:textSize="22sp" >
</TextView>
</RelativeLayout>
</LinearLayout>
<LinearLayout android:layout_height="0dp"
android:layout_weight="1"
android:layout_width="match_parent"
android:id="#+id/filaBottom">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ff00ff"
android:orientation="vertical" >
<ImageView
android:id="#+id/ivBottle4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:background="#drawable/ic_launcher"
android:src="#drawable/bottle_trans" />
<TextView
android:id="#+id/tvBottle4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="top|center"
android:text="vino"
android:textAlignment="center"
android:textSize="22sp" >
</TextView>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:layout_centerInParent="true"
android:id="#+id/ivBottle5"
android:layout_width="wrap_content"
android:background="#drawable/ic_launcher"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="#drawable/bottle_trans" />
<TextView
android:layout_alignParentBottom="true"
android:id="#+id/tvBottle5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top|center"
android:text="vino"
android:textAlignment="center"
android:textSize="22sp" >
</TextView>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#0000ff"
android:orientation="vertical" >
<ImageView
android:layout_centerInParent="true"
android:id="#+id/ivBottle6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/ic_launcher"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="#drawable/bottle_trans" />
<TextView
android:layout_alignParentBottom="true"
android:id="#+id/tvBottle6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top|center"
android:text="vino"
android:textAlignment="center"
android:textSize="22sp" >
</TextView>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
Also remove unnecessary lines of code.