how to set one linear layout below another linear layout in android - android

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation=""
android:layout_marginTop="40dp" >
<LinearLayout
android:id="#+id/imagecontainlayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
android:background="#drawable/round_bg"
android:orientation="horizontal"
android:padding="10dp" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".75"
android:singleLine="true"
android:text="Status:"
android:textColor="#0060a4"
android:textSize="15dp" />
<TextView
android:id="#+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3.5"
android:textColor="#0060a4"
android:textSize="15dp" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="20dip"
android:layout_height="20dip"
android:layout_weight=".75" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="295dp"
android:layout_height="44dp"
android:background="#drawable/round_bg"
android:orientation="horizontal"
android:padding="10dp" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".75"
android:singleLine="true"
android:text="Status:"
android:textColor="#0060a4"
android:textSize="15dp" />
<TextView
android:id="#+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3.5"
android:textColor="#0060a4"
android:textSize="15dp" />
</LinearLayout>
</LinearLayout>
Here is my Xml am trying to set imagecontainlayout linear layout to another linear layout containing another linear layout with some gap but i dont know where am doing mistake in my code my current screen is coming like this .
my current screen is coming like this while i want there first layout below another layout with some gap please help me where am doing mistake.

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/round_bg"
android:orientation="horizontal"
android:padding="10dp" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".75"
android:singleLine="true"
android:text="Step:"
android:textColor="#0060a4"
android:textSize="15dp" />
<TextView
android:id="#+id/step"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3.5"
android:textColor="#0060a4"
android:textSize="15dp" />
</LinearLayout>
</LinearLayout>
use this code it will Help u .

Related

center relativeLayout in linearLayout

I've a linear layout with inside 3 different relative layout.I want to divide in 3 equals parts this root linear layout.I've set the weight sum to 3 in linear layout and set to 0 the width for each relative.But when i hide one of this relative,the other two are not centered as expected.This is the xml code `
<RelativeLayout
android:id="#+id/OffertaBassa"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:visibility="visible" >
<TextView
android:id="#+id/offertaPiuBassa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:layout_gravity="top|center"
android:layout_margin="5dp"
android:gravity="center"
android:text="#string/scheda_dettaglio_richiesta_offerta_migliore"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/macingo_gabriele_testo"
android:textSize="12dp"
android:visibility="visible" />
<TextView
android:id="#+id/PrezzoBasso"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/offertaPiuBassa"
android:layout_centerInParent="true"
android:layout_gravity="center_vertical|center_horizontal|top"
android:gravity="center"
android:text="€"
android:textColor="#color/macingo_drawer_listItem_selected"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/ivaEsclusaLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/PrezzoBasso"
android:layout_centerInParent="true"
android:layout_gravity="center_vertical|center_horizontal|top"
android:text="IVA esclusa"
android:textColor="#color/macingo_card_text_light"
android:textSize="10sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/NumeroPreventivi"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:visibility="visible" >
<TextView
android:id="#+id/preventiviRicevuti"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:layout_gravity="top|center"
android:layout_margin="5dp"
android:gravity="center"
android:text="#string/scheda_dettaglio_richiesta_preventivi_ricevuti"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/macingo_gabriele_testo"
android:textSize="12dp"
android:visibility="visible" />
<TextView
android:id="#+id/numeroPreventivi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/preventiviRicevuti"
android:layout_centerInParent="true"
android:layout_gravity="center_vertical|center_horizontal|top"
android:text="N°"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/macingo_card_text"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/prezzoriferimento"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:visibility="visible" >
<TextView
android:id="#+id/prezzoRiferimento"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:layout_gravity="top|center"
android:layout_margin="5dp"
android:gravity="center"
android:text="#string/scheda_dettaglio_richiesta_prezzo_riferimento"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/macingo_gabriele_testo"
android:textSize="12sp"
android:visibility="visible" />
<TextView
android:id="#+id/prezzoDiriferimento"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/prezzoRiferimento"
android:layout_centerInParent="true"
android:layout_gravity="center_vertical|center_horizontal|top"
android:text="€"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/macingo_card_text"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/TextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/prezzoDiriferimento"
android:layout_centerInParent="true"
android:layout_gravity="center_vertical|center_horizontal|top"
android:text="IVA esclusa"
android:textColor="#color/macingo_card_text_light"
android:textSize="10sp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>`
How can i solve this situation?I've tried to set gravity but with no result.
Thanks
You can do something like this.
Please go through this Code.
<?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:gravity="center_horizontal"
android:orientation="vertical"
android:weightSum="3" >
<RelativeLayout
android:id="#+id/OffertaBassa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:visibility="visible" >
<TextView
android:id="#+id/offertaPiuBassa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:layout_gravity="top|center"
android:layout_margin="5dp"
android:gravity="center"
android:text="scheda_dettaglio_richiesta_offerta_migliore"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textSize="12dp"
android:visibility="visible" />
<TextView
android:id="#+id/PrezzoBasso"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/offertaPiuBassa"
android:layout_centerInParent="true"
android:layout_gravity="center_vertical|center_horizontal|top"
android:gravity="center"
android:text="€"
android:textColor="#000000"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/ivaEsclusaLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/PrezzoBasso"
android:layout_centerInParent="true"
android:layout_gravity="center_vertical|center_horizontal|top"
android:text="IVA esclusa"
android:textColor="#000000"
android:textSize="10sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/NumeroPreventivi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:visibility="visible" >
<TextView
android:id="#+id/preventiviRicevuti"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:layout_gravity="top|center"
android:layout_margin="5dp"
android:gravity="center"
android:text="scheda_dettaglio_richiesta_preventivi_ricevuti"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textSize="12dp"
android:visibility="visible" />
<TextView
android:id="#+id/numeroPreventivi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/preventiviRicevuti"
android:layout_centerInParent="true"
android:layout_gravity="center_vertical|center_horizontal|top"
android:text="N°"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/prezzoriferimento"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:visibility="visible" >
<TextView
android:id="#+id/prezzoRiferimento"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:layout_gravity="top|center"
android:layout_margin="5dp"
android:gravity="center"
android:text="scheda_dettaglio_richiesta_prezzo_riferimento"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textSize="12sp"
android:visibility="visible" />
<TextView
android:id="#+id/prezzoDiriferimento"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/prezzoRiferimento"
android:layout_centerInParent="true"
android:layout_gravity="center_vertical|center_horizontal|top"
android:text="€"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/TextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/prezzoDiriferimento"
android:layout_centerInParent="true"
android:layout_gravity="center_vertical|center_horizontal|top"
android:text="IVA esclusa"
android:textColor="#000000"
android:textSize="10sp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
You have to visibility gone of Relative layout.
NumeroPreventivi.setVisibility(View.GONE);
have you visibility gone or invisible of Relative Layout?because if you doing visibility gone of layout then its work perfectly and if you are doing visibility invisible then this layout existence true. i mean this layout take area of layout.
at run time you have to change weight sum of layouts.

How to align image at extreme left of listitem?

I have an ImageView (android:id="#+id/unreadmail) which i want to show on extreme left of ListItem as shown in image. But it is not aligning properly. Any idea if i am missing anything ?
<LinearLayout
android:id="#+id/Text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/emailsubject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center"
android:singleLine="true"
android:text="abcd"
android:textColor="#444444"
android:textSize="18sp" />
<TextView
android:id="#+id/emailcontent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/emailsubject"
android:layout_below="#id/emailsubject"
android:ellipsize="marquee"
android:gravity="center"
android:singleLine="true"
android:text="defg"
android:textColor="#444444"
android:textSize="14sp" />
</LinearLayout>
<ImageView
android:id="#+id/unreademail"
android:layout_width="2dip"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/emailsubject"
android:layout_centerVertical="true"
android:background="#8A6175"
android:visibility="invisible" />
<TextView
android:id="#+id/rcvdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingRight="20dip"
android:textColor="#313132"
android:textSize="12sp" />
Use this:
<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"
tools:context=".MainActivity"
tools:ignore="ObsoleteLayoutParam,ContentDescription,UselessLeaf,UselessParent" >
<LinearLayout
android:id="#+id/Text"
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal" >
<ImageView
android:id="#+id/unreademail"
android:layout_width="15dip"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/ic_launcher"
android:visibility="visible" />
<LinearLayout
android:id="#+id/Text"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_marginLeft="20dp"
android:orientation="vertical" >
<TextView
android:id="#+id/emailsubject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center"
android:singleLine="true"
android:text="abcd"
android:textColor="#444444"
android:textSize="18sp" />
<TextView
android:id="#+id/emailcontent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/emailsubject"
android:layout_below="#id/emailsubject"
android:ellipsize="marquee"
android:gravity="center"
android:singleLine="true"
android:text="defg"
android:textColor="#444444"
android:textSize="14sp" />
</LinearLayout>
<RelativeLayout
android:id="#+id/Text1"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:gravity="right"
android:layout_gravity="right"
android:orientation="horizontal" >
<TextView
android:id="#+id/rcvdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="35dp"
android:text="Date"
android:textColor="#000"
android:textSize="12sp" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
I think you should be using a relative layout at the top level (possibly not included in your code).
You cannot use 'to the left of' when the elements are at different levels in the heirarchy.
Thus I would start with your little icon left aligned to the parent and put the edit box (in the same relative view) 'to the right of' the icon.
This is the code sample for you there is no need to write the weight property if add the screenshot or the supported image how exactly you want then i can give you proper answer
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/unreademail"
android:layout_marginLeft="10dip"
android:orientation="vertical">
<TextView
android:id="#+id/emailsubject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center"
android:singleLine="true"
android:text="abcd"
android:textColor="#444444"
android:textSize="18sp" />
<TextView
android:id="#+id/emailcontent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/emailsubject"
android:layout_below="#id/emailsubject"
android:ellipsize="marquee"
android:gravity="center"
android:singleLine="true"
android:text="defg"
android:textColor="#444444"
android:textSize="14sp" />
</LinearLayout>
<ImageView
android:id="#+id/unreademail"
android:layout_width="2dip"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:layout_marginBottom="5dip"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#8A6175"
android:visibility="invisible" />
<TextView
android:id="#+id/rcvdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingRight="20dip"
android:textColor="#313132"
android:textSize="12sp" />
</RelativeLayout>

xml centered textview to much to left

I try to create somekind of stroke on top of my screen which displays 4 things. An backbutton on the left, the level name in the center and scoreInfoOne and scoreInfoTwo on the right, but below each other. I use following code, but the strange thing is that the level name doesn't appear to be centered, the longer the value of scoreInfoTwo is, the more the level name is on the left. Any ideas?
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="35dp"
android:background="#25ab89"
android:orientation="horizontal"
android:weightSum="4" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/ivBackButton"
android:layout_width="18dp"
android:layout_height="18dp"
android:src="#drawable/arrow" />
</LinearLayout>
<TextView
android:id="#+id/tvScoreBoard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="2"
android:gravity="center"
android:text="level"
android:textColor="#ffffff"
android:textSize="18dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical"
android:paddingRight="2dp" >
<TextView
android:id="#+id/tvScoreInfoOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="0/30"
android:textColor="#ffffff"
android:textSize="12dp" />
<TextView
android:id="#+id/tvScoreInfoTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="score:"
android:textColor="#ffffff"
android:textSize="12dp" >
</TextView>
</LinearLayout>
Your child views must set the layout_width to zero:
android:layout_width="0px"
So your layout would then look like:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="35dp"
android:background="#25ab89"
android:orientation="horizontal"
android:weightSum="4" >
<LinearLayout
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/ivBackButton"
android:layout_width="18dp"
android:layout_height="18dp"
android:src="#drawable/arrow" />
</LinearLayout>
<TextView
android:id="#+id/tvScoreBoard"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="2"
android:gravity="center"
android:text="level"
android:textColor="#ffffff"
android:textSize="18dp" />
<LinearLayout
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical"
android:paddingRight="2dp" >
<TextView
android:id="#+id/tvScoreInfoOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="0/30"
android:textColor="#ffffff"
android:textSize="12dp" />
<TextView
android:id="#+id/tvScoreInfoTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="score:"
android:textColor="#ffffff"
android:textSize="12dp" >
</TextView>
</LinearLayout>
First off, you cannot use android:layout_gravity="anything" in a LinearLayout. For LinearLayouts you use the weights to define how much space you want to use. For what you are trying to do, I suggest using a RelativeLayout then you can just define where you want your TextView or other items by using android:layout_below="#+id/other_textview and there are lots of android:layout_[direction] to choose from, and you can use layout_gravity="center_horizontal" with these.
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="35dp"
android:background="#25ab89">
<ImageView
android:id="#+id/ivBackButton"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="#drawable/arrow" />
<TextView
android:id="#+id/tvScoreBoard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_below="#id/ivBackButton"
android:gravity="center"
android:text="level"
android:textColor="#ffffff"
android:textSize="18dp" />
<TextView
android:id="#+id/tvScoreInfoOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_below="#id/tvScoreBoard"
android:alignParentRight="true"
android:text="0/30"
android:textColor="#ffffff"
android:textSize="12dp" />
<TextView
android:id="#+id/tvScoreInfoTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_below="#id/tvScoreInfoTwo"
android:alignParentRight="true"
android:text="score:"
android:textColor="#ffffff"
android:textSize="12dp" />
</RelativeLayout>

Which layout have to use

I am new to android app development.I am developing an android app which is having a design like the following one.Which layout I have to use.If I use Linear layout I cannot place "Product Amount" Textview and Editbox in a stright line.Please help me to solve this.
you can do this using Linear Layout also
Try below code
<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">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Product Amount"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/editText1"
android:layout_width="140dp"
android:layout_marginLeft="10dp"
android:layout_height="wrap_content"
>
<requestFocus />
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<EditText
android:id="#+id/editText2"
android:layout_width="80dp"
android:layout_marginLeft="5dp"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="%"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="TextView" />
<EditText
android:id="#+id/editText3"
android:layout_marginLeft="5dp"
android:layout_width="80dp"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<EditText
android:id="#+id/editText4"
android:layout_width="80dp"
android:layout_marginLeft="5dp"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="%"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="TextView" />
<EditText
android:id="#+id/editText6"
android:layout_marginLeft="5dp"
android:layout_width="80dp"
android:layout_height="wrap_content"
/>
</LinearLayout>
See below it's give me output like this
You will have to use more than one layout. Your xml will be something like this.
Linear Layout main (Vertical)
Linear Layout1 (Horizontal) - for first row.
Layout 1 ends
Linear Layout2 (Horizontal) - for second row.
Layout 2 ends
Linear Layout3 (Horizontal) - for third row.
Layout 3 ends
Text Sale Amt
Layout main ends
Edit:
<?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:id="#+id/l1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dip"
android:layout_marginRight="3dip"
android:layout_weight="1"
android:padding="3dip"
android:text="Name" />
<EditText
android:id="#+id/nameedt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dip"
android:layout_marginRight="3dip"
android:layout_weight="1"
android:inputType="textNoSuggestions"
android:padding="3dip" />
</LinearLayout>
<LinearLayout
android:id="#+id/l2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/pwd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dip"
android:layout_marginRight="3dip"
android:padding="3dip"
android:layout_weight="1"
android:text="Password" />
<EditText
android:id="#+id/pwdedt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dip"
android:layout_marginRight="3dip"
android:inputType="textNoSuggestions"
android:layout_weight="1"
android:padding="3dip" />
</LinearLayout>
<TextView
android:id="#+id/pwdhint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dip"
android:layout_marginRight="3dip"
android:padding="3dip"
android:layout_weight="1"
android:text="PasswordHint : HINT"
android:layout_gravity="center"/>
</LinearLayout>
You Should use TableLayout, with First Row Having four columns, use col span to extend a column for two columns, add View, where Cell isnt exist.

Adding and image beside a spinner in an android layout

I just want to add an image beside the Spinner in my layout. I tried align:layout_gravity = "right" for the image, but this moved the image to the right side in the layout and below the Spinner present in the same layout. What I want is for the image to be displayed exactly besides the Spinner. Below is the xml layout file:
<LinearLayout
android:id="#+id/topLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:background="#color/headingBgColor"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="#+id/yourName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Group"
android:textColor="#color/black" />
</ImageView>
</LinearLayout>
<LinearLayout
android:id="#+id/bottomLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:orientation="horizontal"
android:padding="5sp" >
<Button
android:id="#+id/deleteBlockLog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tasks"
android:textSize="#dimen/font_size_10"
android:textStyle="bold" />
<Button
android:id="#+id/deleteBlockLog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Messages"
android:textSize="#dimen/font_size_10"
android:textStyle="bold" />
<Button
android:id="#+id/deleteBlockLog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Groups"
android:textSize="#dimen/font_size_10"
android:textStyle="bold" />
<Button
android:id="#+id/deleteBlockLog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Notes"
android:textSize="#dimen/font_size_10"
android:textStyle="bold" />
<Button
android:id="#+id/deleteBlockLog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MyProfile"
android:textSize="#dimen/font_size_10"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/centerLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/topLayout"
android:orientation="vertical"
android:padding="10sp" >
<Spinner
android:id="#+id/spinner1"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:paddingTop="20dip" />
<ImageView
android:id="#+id/imageButton"
android:layout_width="100dp"
android:layout_height="70dp"
android:layout_gravity="right"
android:src="#drawable/contacts" />
<LinearLayout
android:id="#+id/centerLqayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10sp" >
<CheckBox
android:id="#+id/sms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SMS"
android:textColor="#color/black" />
<CheckBox
android:id="#+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email"
android:textColor="#color/black" />
</LinearLayout>
<EditText
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:layout_height="140dp"
android:gravity="top"
android:inputType="textPostalAddress" >
<requestFocus />
</EditText>
<Button
android:id="#+id/deleteBlockLog1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Send"
android:textSize="#dimen/font_size_15" />
</LinearLayout>
LinearLayout with orientation set to vertical will put the child views one below other. You have two options:
You either wrap the Spinner and the ImageView in another LinearLayout with orientation set to horizontal so the two views end up on the same line.
Example:
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:orientation="horizontal">
<Spinner
android:id="#+id/spinner1"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:paddingTop="20dip" />
<ImageView
android:id="#+id/imageButton"
android:layout_width="100dp"
android:layout_height="70dp"
android:src="#drawable/contacts" />
</LinearLayout>
You use a layout that allows the children to be placed relative to others(like a RelativeLayout) instead of the parent LinearLayout with the id centerLayout.

Categories

Resources