RelativeLayout layout_below issue in android - android

I am having an issue with getting my date TextView to be below my unit TextView when the activity name is too long in the rows for my ListView.
Here is my row layout code for my listview:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Name"
android:id="#+id/activityName"
android:textSize="25dp"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/pound"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="unit"
android:id="#+id/unit"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/"
android:id="#+id/slash"
android:layout_toLeftOf="#+id/unit"
android:layout_centerVertical="true"
android:layout_marginRight="2dp"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Number"
android:id="#+id/number"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/slash"
android:layout_marginRight="5dp"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#"
android:id="#id/pound"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/number"
android:layout_marginRight="2dp"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date"
android:id="#+id/date"
android:layout_below="#+id/unit"
android:layout_alignRight="#+id/unit"
android:textSize="10sp" />
</RelativeLayout>
My ListView rows look like this:
Question:
How do I get my date TextView to always be below my unit TextView? Also for the pound, number, slash, and unit TextViews to be all on the same line and all above the date Textview. As well as the activityName TextView to be the left of the pound TextView so it does not overlap with the pound, number, slash, and unit TextViews. Like what the walk and exercise rows look like.

Take a LinearLayout for right sided items(unit,date,slash etc.)
put it in relative layout and set as align_parentright = "true"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dip"
android:paddingRight="10dip" >
<TextView
android:id="#+id/activityName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/verticalLayout"
android:text="New Name"
android:textSize="25sp" />
<LinearLayout
android:id="#id/verticalLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/pound"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="2dp"
android:text="#"
android:textSize="20sp" />
<TextView
android:id="#+id/unit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:text="unit"
android:textSize="20sp" />
<TextView
android:id="#+id/slash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="2dp"
android:text="/"
android:textSize="20sp" />
<TextView
android:id="#+id/number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Number"
android:textSize="20sp" />
</LinearLayout>
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Date"
android:textSize="10sp" />
</LinearLayout>
</RelativeLayout>

Try putting the pound TextView & the date TextView inside a vertical LinearLayout, and then have the LinearLayout be aligned to center vertically and to the right.
Hope this helps :)

// try this
<?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:padding="5dp"
android:gravity="center">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="New Name"
android:id="#+id/activityName"
android:textSize="25dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#"
android:id="#+id/pound"
android:layout_marginRight="2dp"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Number"
android:id="#+id/number"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/"
android:id="#+id/slash"
android:layout_marginRight="5dp"
android:textSize="20dp" />
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center"
android:layout_marginLeft="5dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="unit"
android:id="#+id/unit"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date"
android:id="#+id/date"
android:layout_marginTop="3dp"
android:textSize="10sp" />
</LinearLayout>
</LinearLayout>

If you have such problem in ListView make sure that you use proper inflation method. Parent view group must be specified for correct inflation.
mLayoutInflater.inflate(R.layout.listitem, parent, false);
Instead of
mLayoutInflater.inflate(R.layout.listitem, null);

Related

placing a text right beside another text

I have designed a simple layout in android where I needed to place an element right beside another element. On attempting to do that the textview jumps below the textview that is supposed to be at the side of it. Here is my approach
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#id/movieImage"
android:orientation="vertical">
<TextView
android:id="#+id/nameTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Name"
android:textSize="20sp" />
<TextView
android:id="#+id/1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#id/movieImage"
android:text="Up"
android:textSize="15sp" />
I want this textview to be placed beside the above textview
<TextView
android:id="#+id/2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/1"
android:text="Two"
android:textSize="15sp" />
</LinearLayout>
Thanks in assistance
Try this xml
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#id/movieImage"
android:orientation="vertical">
<TextView
android:id="#+id/nameTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Name"
android:textSize="20sp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#id/movieImage"
android:text="Up"
android:textSize="15sp" />
<TextView
android:id="#+id/2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/1"
android:text="Two"
android:textSize="15sp" />
</LinearLayout>
</LinearLayout>
LinearLayouts have and orientation property, that indicates how they elements will grow.
You can nest LinearLayout inside another one if you want to mix orientations, like this:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#id/movieImage"
android:orientation="vertical">
<TextView
android:id="#+id/nameTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Name"
android:textSize="20sp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#id/movieImage"
android:text="Up"
android:textSize="15sp" />
<TextView
android:id="#+id/2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Two"
android:textSize="15sp" />
</LinearLayout>
</LinearLayout>
Try
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#id/movieImage"
android:orientation="vertical">
<TextView
android:id="#+id/nameTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Name"
android:textSize="20sp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#id/movieImage"
android:orientation="horizontal">
<TextView
android:id="#+id/1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#id/movieImage"
android:text="Up"
android:textSize="15sp" />
<TextView
android:id="#+id/2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/1"
android:text="Two"
android:textSize="15sp" />
</LinearLayout>
</LinearLayout>

Text View Above overrides Text View below it

I have a textView in a list item with another text view below it.
I am facing one problem again and again that when text increases . text view above overrides my text view below or text view below comes on top of text view above.
My XML in RelativeLayout is :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tp_activity_wise_badge_fragment_each_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/tp_White"
android:minHeight="60dp">
<TextView
android:id="#+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginLeft="23dp"
android:layout_marginStart="23dp"
android:text="Loading Title..."
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#737574"
android:textSize="15dp"
android:textStyle="bold" />
<TextView
android:id="#+id/textview3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textview1"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textview1"
android:layout_centerVertical="true"
android:layout_marginEnd="23dp"
android:layout_marginRight="23dp"
android:background="#color/tp_White"
android:gravity="center_vertical|center_horizontal"
android:maxLines="2"
android:text="Loading..."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#737574"
android:textSize="15dp" />
<TextView
android:id="#+id/textview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loading Subtitle..."
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/tp_inactive_channel_text_color"
android:textSize="11dp"
android:layout_below="#+id/textview1"
android:layout_alignLeft="#+id/textview1"
android:layout_alignStart="#+id/textview1" />
i know this is very basic problem but this is very undefined for me and i am not able to position this views such that they dont cut each other.
Any help will be appreciated.
You need to use layout_alignParentRight in your code.
its not proper way you set margin to set view
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tp_activity_wise_badge_fragment_each_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/tp_White"
android:minHeight="60dp">
<TextView
android:id="#+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loading Title..."
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#737574"
android:textSize="15dp"
android:textStyle="bold" />
<TextView
android:id="#+id/textview3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/textView1"
android:layout_alignParentRight="true"
android:gravity="right"
android:background="#color/tp_White"
android:maxLines="2"
android:text="Loading..."
android:textColor="#737574"
android:textSize="15dp" />
<TextView
android:id="#+id/textview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loading Subtitle..."
android:textSize="11dp"
android:layout_below="#id/textview1"
/>
What are you trying to achieve by writing android:layout_alignTop="#+id/textview1" and at same time android:layout_alignBottom="#+id/textview1".
Instead you can try android:layout_below="#+id/textview1" this will align your textview vertically.
You should use LinearLayout (just copy and paste it)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tp_activity_wise_badge_fragment_each_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="25dp"
>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_marginBottom="10dp"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loading Title..."
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#737574"
android:textSize="15dp"
android:textStyle="bold" />
<TextView
android:id="#+id/textview3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:text="Loading..."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#737574"
android:textSize="15dp" />
</LinearLayout>
<TextView
android:id="#+id/textview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loading Subtitle..."
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="11dp"
/>
</LinearLayout>

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.

Prevent a view from getting outside of the screen

I'm working with the Google Maps API v2, and I overrided getInfoContents() from InfoWindowAdapter for having a customized InfoWindow. Inside getInfoContents()I inflate an xml containing an ImageView, and three TextViews.
My problem comes when the text that is set inside the snippet is larger than the view, then the count TV it's set outside the view. This is illustrated above with some screenshots.
Here my xml layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/categoryIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignBottom="#+id/count"
android:src="#drawable/ic_launcher"/>
<LinearLayout
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_toRightOf="#+id/categoryIcon"
android:layout_centerVertical="true"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:textStyle="bold" />
<TextView
android:id="#+id/snippet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Snippet" />
</LinearLayout>
<TextView
android:id="#+id/count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#111177"
android:text="0"
android:textSize="20sp"
android:padding="10dp"
android:textColor="#FFF"
android:layout_toRightOf="#+id/text"
android:singleLine="true" />
</RelativeLayout>
How can I change this layout for getting the count TextView inside of the screen, and the snippet in multiline?
I want to always show the count TextView.
UPDATE:
Finally with the answer of Simon Marquis I realized a way to accomplish this. Here the new code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/categoryIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignBottom="#+id/text"
android:src="#drawable/ic_launcher"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/text"
android:orientation="horizontal"
android:gravity="center_vertical"
android:layout_toRightOf="#+id/categoryIcon">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:textStyle="bold" />
<TextView
android:id="#+id/snippet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Snippeta" />
</LinearLayout>
<TextView
android:id="#+id/count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#111177"
android:text="0"
android:textSize="20sp"
android:padding="10dp"
android:textColor="#FFF"
android:singleLine="true" />
</LinearLayout>
</RelativeLayout>
You should add this to the LinearLayout:
android:layout_width="0dp"
android:layout_weight="1"
The new layout file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/categoryIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignBottom="#+id/count"
android:src="#drawable/ic_launcher"/>
<LinearLayout
android:id="#+id/text"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_toRightOf="#+id/categoryIcon"
android:layout_centerVertical="true"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:textStyle="bold" />
<TextView
android:id="#+id/snippet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Snippet" />
</LinearLayout>
<TextView
android:id="#+id/count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#111177"
android:text="0"
android:textSize="20sp"
android:padding="10dp"
android:textColor="#FFF"
android:layout_toRightOf="#+id/text"
android:singleLine="true" />
</RelativeLayout>
One solution if you want that the count TextView always appears at right is the following:
Put the count Text View before the LinearLayout and add
android:layout_alignParentRight="true"
And add android:layout_toLeftOf="#id/count" in the Linear Layout
<TextView
android:id="#+id/count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#00F"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#id/count"
android:orientation="vertical" >
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/snippet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>

How can I place two TextView on a same line, in a vertical layout

I am trying to display an ImageView with 4 textView. "Title" "times" "age" and "informations". All of them are in global horizontal layout. And the 4 textView are in a vertical layout. The thing is that I want to have "times" and "age" one the same line. But it can't be with a vertical layout.
Here is my xml code :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imgLink"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Titre"
android:textSize="8sp"
android:textStyle="bold" />
<TextView
android:id="#+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8sp"
android:text="age" />
<TextView
android:id="#+id/age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8sp"
android:text="age" />
<TextView
android:id="#+id/information"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:textSize="8sp"
android:text="phrase" />
</LinearLayout>
Thanks
Here you go
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imgLink"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Titre"
android:textSize="8sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Time"
android:textSize="8sp" />
<TextView
android:id="#+id/age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="age"
android:textSize="8sp" />
</LinearLayout>
<TextView
android:id="#+id/information"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:text="phrase"
android:textSize="8sp" />
</LinearLayout>
Put LinearLayout as a parent to both textviews and set orientation of that LinearLayout as Horizontal..
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8sp"
android:text="time" />
<TextView
android:id="#+id/age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8sp"
android:text="age" />
<LinearLayout/>
as I told there is one more approach using Relative layout the second one
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:textSize="8sp"
android:textStyle="bold"
android:layout_alignParentTop="true" />
<TextView
android:id="#+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8sp"
android:text="time"
android:layout_below="#id/title" />
<TextView
android:id="#+id/age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8sp"
android:text="age"
android:layout_below="#id/title"
android:layout_toRightOf="#id/time" />
<TextView
android:id="#+id/information"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:textSize="8sp"
android:text="phrase"
android:layout_below="#id/time" />
Use the Graphical Layout, and place the age and the time fiels on the same ligne..much easier

Categories

Resources