Android LinearLayout to align contents into different sides - android

I'm still beginner at different Android layouts. Here is simple linear layout:
<LinearLayout
android:layout_height="50dp"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:gravity="end"
android:padding="5dp">
<ImageButton
android:id="#+id/bt_template"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_template_button"
android:scaleType="fitCenter"
android:background="#ffffffff"
android:contentDescription="Choose template"/>
<ImageButton
android:id="#+id/bt_captureImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_camera_button"
android:scaleType="fitCenter"
android:background="#ffffffff"
android:contentDescription="Choose template"/>
<Button
style="#style/MyRedButton"
android:layout_margin="0dp"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:text="#string/str_new_mail_activity_button_send"
android:id="#+id/bt_send" />
</LinearLayout>
I want 2 buttons to go left and third button go right. How do I do that?
Blue buttons need to be on left side and red button on right side. How can I do that?

This is a possible option for using LinearLayout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="center_vertical"
android:layout_height="50dp"
android:layout_width="match_parent"
android:orientation="horizontal"
android:padding="5dp">
<ImageButton
android:background="#ffffffff"
android:contentDescription="Choose template"
android:id="#+id/bt_template"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:scaleType="fitCenter"
android:src="#drawable/ic_template_button" />
<ImageButton
android:background="#ffffffff"
android:contentDescription="Choose template"
android:id="#+id/bt_captureImage"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:scaleType="fitCenter"
android:src="#drawable/ic_camera_button" />
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<Button
style="#style/MyRedButton"
android:id="#+id/bt_send"
android:layout_height="match_parent"
android:layout_margin="0dp"
android:layout_width="wrap_content"
android:text="#string/str_new_mail_activity_button_send" />
</LinearLayout>

If you must use LinearLayout, give the red button a weight of 1 (so it will hog space) and make sure it has a gravity to the right if that's what you need.
android:layout_weight="1"
android:layout_gravity="right"

Check this out:
<RelativeLayout
android:layout_height="50dp"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:gravity="end"
android:padding="5dp">
<ImageButton
android:id="#+id/bt_template"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:scaleType="fitCenter"
android:background="#ffffffff"
android:layout_alignParentLeft="true"
android:contentDescription="Choose template"/>
<ImageButton
android:id="#+id/bt_captureImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:scaleType="fitCenter"
android:layout_toRightOf="#id/bt_template"
android:background="#ffffffff"
android:contentDescription="Choose template"/>
<Button
android:layout_margin="0dp"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:text="send"
android:layout_alignParentRight="true"
android:id="#+id/bt_send" />
</RelativeLayout>

Related

Gridlayout pictures to small eclipse

I have a gridLayout form 3 by 3. with in there imagebuttons.
the grid is working, but i want the images to fill the weight of the parent.
this is the code i have:
<LinearLayout 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"
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="com.example.tict.MainActivity"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
<GridLayout
android:id="#+id/mygrid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:columnCount="3"
android:rowCount="3" >
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<ImageButton
android:id="#+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<ImageButton
android:id="#+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<ImageButton
android:id="#+id/imageButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<ImageButton
android:id="#+id/imageButton5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"/>
<ImageButton
android:id="#+id/imageButton6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"/>
<ImageButton
android:id="#+id/imageButton7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<ImageButton
android:id="#+id/imageButton8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<ImageButton
android:id="#+id/imageButton9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</GridLayout>
I want to keep the gridLayout if that is posible.
EDIT: I want 3 image buttons at the top row. All 3 being 1/3 weight of the parent.
You are using layout_width and layout_height properties with
wrap_content : , which means that the view wants to be just big enough to enclose its content (plus padding)
change to:
match_parent : which means that the view wants to be as big as its parent (minus padding)
I could't find a solution, so made a nested LiniarLayout.
Part of the new code is now:
<LinearLayout 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"
android:orientation="vertical"
android:background="#drawable/background">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/TG" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/ib_1"
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_weight=".30"
android:background="#android:color/white"
android:contentDescription="#string/btn"
android:onClick="onClick"
android:scaleType="fitXY"
android:layout_margin="5dp"
/>

5 sided dice like layout in Android

I'm currently working on an Android app and I would like to make a nice layout.
What I'm trying to achieve is the following layout:
The circles will be of equal size ofcourse. Besides that i need to be able to click them so they need to be buttons or imageviews.
What would be the best approach to achieve this kind of layout?
You could use a RelativeLayout, and say where each of the dots is supposed to be in relation to each of the others.
You could also use a LinearLayout, creating three 'rows' of buttons, the top and bottom rows containing two of the 'dots' and the middle one containing one in the center.
The layout would look something like this:
And the code would be something like this:
<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="wrap_content"
android:orientation="horizontal" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/dot"
android:background="#android:color/transparent"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/dot2"
android:background="#android:color/transparent"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/dot3"
android:background="#android:color/transparent"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/dot4"
android:background="#android:color/transparent"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/dot5"
android:background="#android:color/transparent"/>
</LinearLayout>
</LinearLayout>
Try this..
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:src="#drawable/ic_launcher"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
/>
<ImageView
android:src="#drawable/ic_launcher"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:src="#drawable/ic_launcher"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_centerInParent="true"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:src="#drawable/ic_launcher"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
/>
<ImageView
android:src="#drawable/ic_launcher"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
/>
</RelativeLayout>
</LinearLayout>
Use a nest of LinearLayout or RelativeLayout. To use the images as button, then use ImageView and indicate in the xml corresponding ID for each image so you can use it in your activity.

Two LinearLayouts with same background colour appear different in the parent view

I have this layout:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#android:color/black"
android:gravity="center_horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.digitaliridium.tides.NVLibrary.NVGlobeView
android:id="#+id/globeView"
android:src="#drawable/icon"
android:background="#color/nvglobebackground"
android:scaleType="matrix"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:background="#color/paneltransparenciesbackground"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/globeViewPortName"
android:textSize="22dp"
android:textStyle="bold"
android:background="#android:color/transparent"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:layout_width="fill_parent"
android:layout_height="26dp"/>
<TextView
android:id="#+id/globeViewLocation"
android:textSize="12dp"
android:layout_marginTop="3dp"
android:layout_marginLeft="5dp"
android:background="#android:color/transparent"
android:layout_width="fill_parent"
android:layout_height="18dp"/>
<TextView
android:id="#+id/globeViewPortType"
android:textSize="12dp"
android:background="#android:color/transparent"
android:layout_marginLeft="5dp"
android:layout_width="fill_parent"
android:layout_height="18dp"/>
</LinearLayout>
<LinearLayout
android:background="#color/paneltransparenciesbackground"
android:orientation="vertical"
android:layout_gravity="bottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:background="#color/paneltransparenciesbackground"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageButton
android:id="#+id/indicatorMode"
android:src="#drawable/nv_selector"
android:background="#android:color/transparent"
android:layout_marginLeft="10dp"
android:layout_width="50dp"
android:layout_height="50dp"/>
<ImageButton
android:id="#+id/homePort"
android:src="#drawable/nv_home_port"
android:background="#android:color/transparent"
android:layout_toRightOf="#id/indicatorMode"
android:layout_marginLeft="20dp"
android:layout_width="50dp"
android:layout_height="50dp"/>
<ImageButton
android:id="#+id/gps"
android:src="#drawable/nv_gpsarrow_white"
android:background="#android:color/transparent"
android:layout_centerInParent="true"
android:layout_width="50dp"
android:layout_height="50dp"/>
</RelativeLayout>
<RelativeLayout
android:background="#color/paneltransparenciesbackground"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/viewPointLocation"
android:textSize="12dp"
android:background="#android:color/transparent"
android:gravity="center_vertical"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="30dp"/>
<TextView
android:id="#+id/scale"
android:textSize="12dp"
android:layout_marginLeft="20dp"
android:gravity="center_vertical"
android:layout_toRightOf="#id/viewPointLocation"
android:background="#android:color/transparent"
android:layout_width="wrap_content"
android:layout_height="30dp"/>
<TextView
android:id="#+id/distance"
android:textSize="12dp"
android:layout_marginRight="10dp"
android:layout_alignParentRight="true"
android:gravity="center_vertical"
android:background="#android:color/transparent"
android:layout_width="wrap_content"
android:layout_height="30dp"/>
</RelativeLayout>
</LinearLayout>
<ImageButton
android:id="#+id/flipView"
android:layout_marginTop="300dp"
android:layout_gravity="bottom"
android:layout_marginBottom="100dp"
android:layout_width="80dp"
android:layout_height="80dp"
android:scaleType="center"
android:src="#drawable/sc_flip"
/>
</FrameLayout>
Here's a shot of the resulting screen
You can see that the semi-transparent panels (the LinearLayouts) appear to have different levels of opaqueness, even though they have the same background colour.
The difference is much more marked on the device screen than it is in the screen cap.
Can anyone spot why?
In the bottom LinearLayout it consists with the RelativeLayout's who also has the same background.
When you put two semi-transparent layers on top of each other they'll look less transparent (it's like they're covering each other)
Drop the background in the RelativeLayout's and they'll look the same.

Android Layout left and right align in horizontal layout

I am have a ImageView and a ImageButton. I have them next to each other in a horizontal layout. I am trying to make it so that the image is left aligned on the screen, and the button is right aligned. I have tried setting gravity but it doesnt seem to make a difference. Where am I going wrong?
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="1"
android:gravity="left"
android:src="#drawable/short_logo" />
<ImageButton
android:id="#+id/terminateSeed"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:background="#null"
android:src="#drawable/unregister_icon" />
</LinearLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="#drawable/ic_launcher" />
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Button" />
</RelativeLayout>
Use...
<?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="horizontal"
android:weightSum="1.0" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginRight="80dp"
android:layout_weight="0.5"
android:gravity="left"
android:src="#drawable/ic_launcher" />
<ImageButton
android:id="#+id/terminateSeed"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="right"
android:layout_marginLeft="80dp"
android:background="#null"
android:src="#drawable/ic_launcher" />
</LinearLayout>
Use This example if you want to use LinearLayout without giving Weight
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
/>
</LinearLayout>
<RelativeLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_alignParentLeft="true"
android:src="#drawable/short_logo" />
<ImageButton
android:id="#+id/terminateSeed"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#null"
android:src="#drawable/unregister_icon" />
</RelativeLayout >
Make imageview and imagebutton wrap_content and set layout_gravity to left and right accordingly.
a RelativeLayout would solve your problem with a snap, but if you still insist on using LinearLayout (just because we're badass and do things the hard way), you do it like this:
Your parent LinearLayout is fill-parent, left-aligned, and horizontally oriented,
and contains your ImageView, and another LinearLayout.
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="left"
Second LinearLayout is fill-parent, right-aligned, and horizontally oriented, and contains your ImageButton.
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="right"
Another approach for LinearLayout, using layout_weight and gravity:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="BUTTON 1"/>
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="BUTTON 2" />
</LinearLayout>

Children in Linear Layout with equal padding

I am currently designing a ButtonBar with 5 buttons (they will all be ImageButtons, but for now, only 3 of them are). This is my first android project so I'm learning as I go along. I'm trying to weight each button equally, without scaling them (have equal padding rather than equal width). This is my code so far:
<LinearLayout
android:id="#+id/back"
android:orientation="horizontal"
android:layout_height="50dip"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:background="#000000"
style="#android:style/ButtonBar"
android:weightSum="5"
>
<ImageButton
android:id="#+id/info_button"
android:padding="20dp"
android:background="#drawable/info"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
/>
<Button
android:id="#+id/wishlist_button"
android:text="#string/wish_label"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:padding="20dp"
android:textSize="15dip"
android:textColor="#b7b7b7"></Button>
<Button
android:id="#+id/buy_button"
android:text="#string/buy_label"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:padding="20dp"
android:textSize="15dip"
android:textColor="#b7b7b7"/>
<ImageButton
android:id="#+id/dislike_button"
android:padding="20dp"
android:background="#drawable/dislike_button"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
/>
<ImageButton
android:id="#+id/like_button"
android:padding="20dp"
android:background="#drawable/like_button"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
/>
This is what it looks like now:
stretched weighted: http://i.imgur.com/MAfjp.png
This is what I want it to look like (closely):
non-stretched equally padded: http://i.imgur.com/vXTEy.png
Thank you for helping. I've been searching for the answer for a while and have tried so much already.
Here it is:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/back"
android:orientation="horizontal"
android:layout_height="50dip"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:background="#000000"
style="#android:style/ButtonBar"
android:gravity="center"
>
<ImageButton
android:id="#+id/info_button"
android:background="#null"
android:src="#drawable/info"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
/>
<Button
android:id="#+id/wishlist_button"
android:text="#string/wish_label"
android:background="#null"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
android:textSize="15dip"
android:textColor="#b7b7b7"></Button>
<Button
android:id="#+id/buy_button"
android:text="#string/buy_label"
android:background="#null"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
android:textSize="15dip"
android:textColor="#b7b7b7"/>
<ImageButton
android:id="#+id/dislike_button"
android:background="#null"
android:src="#drawable/dislike_button"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
/>
<ImageButton
android:id="#+id/like_button"
android:background="#null"
android:src="#drawable/like_button"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
/>
</LinearLayout>
I don't know how style="#android:style/ButtonBar" is set, so if it doesn't show properly try remove it.
You could add a spacer element in between each of the images/buttons and assign the layout_weight to the spacer elements instead of the images/buttons. So it would look something like this:
<LinearLayout
android:id="#+id/back"
android:orientation="horizontal"
android:layout_height="50dip"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:background="#000000"
style="#android:style/ButtonBar"
>
<ImageButton
android:id="#+id/info_button"
android:padding="20dp"
android:background="#drawable/info"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
<LinearLayout
android:layout_height="wrap_content"
android:layout_weight="1" />
/>
<Button
android:id="#+id/wishlist_button"
android:text="#string/wish_label"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="20dp"
android:textSize="15dip"
android:textColor="#b7b7b7"></Button>
<LinearLayout
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:id="#+id/buy_button"
android:text="#string/buy_label"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="20dp"
android:textSize="15dip"
android:textColor="#b7b7b7"/>
<LinearLayout
android:layout_height="wrap_content"
android:layout_weight="1" />
<ImageButton
android:id="#+id/dislike_button"
android:padding="20dp"
android:background="#drawable/dislike_button"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
<LinearLayout
android:layout_height="wrap_content"
android:layout_weight="1" />
<ImageButton
android:id="#+id/like_button"
android:padding="20dp"
android:background="#drawable/like_button"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
</LinearLayout>
This may not be the most elegant solution since it adds several views to your layout, but it's worked for me in the past.
You should consider using only image button with equal size images with equal weight inside your LinearLayout.
Regards,
Stéphane

Categories

Resources