I have an issue trying align textView to the center of layout: when I try to do this - it has a conflict with a button on the left - if text is too long - it become hidden under the button. Text length can be very different and I need it in the center of layout but not under/on the button.
Here is the xml file of activity layout:
<?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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/item_content_action_bar_layout"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#color/colorBlue"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Title"
android:textColor="#color/colorWhite"
android:textAlignment="center"
android:singleLine="true"
android:layout_gravity="center_vertical"
android:textStyle="bold"
android:autoText="false"
android:layout_centerInParent="true"
android:layout_alignWithParentIfMissing="false"
android:layout_alignParentRight="false" />
<ImageButton
android:layout_width="120dp"
android:layout_height="45dp"
android:id="#+id/item_content_back_button"
android:background="#drawable/back_button_selector"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginRight="5dp" />
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/item_content_scroll_view"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:fillViewport="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="125dp"
android:layout_height="125dp"
android:id="#+id/item_content_image"
android:src="#drawable/ic_no_thumbnail"
android:maxHeight="125dp"
android:maxWidth="125dp"
android:layout_alignParentLeft="false"
android:layout_alignParentStart="true"
android:layout_margin="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_subtitle"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Subtitle"
android:layout_alignTop="#+id/item_content_image"
android:layout_toRightOf="#+id/item_content_image"
android:layout_toEndOf="#+id/item_content_image"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_pubdate"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Date"
android:layout_below="#+id/item_content_subtitle"
android:layout_alignLeft="#+id/item_content_subtitle"
android:layout_alignStart="#+id/item_content_subtitle"
android:textSize="10dp"
android:layout_marginTop="10dp" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="blabla"
android:layout_below="#+id/item_content_pubdate"
android:layout_alignStart="#+id/item_content_pubdate"
android:layout_alignParentStart="true"
android:layout_margin="10dp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Try using LinearLayout with layout-weight for this to avoid conflict. Change your first relativelayout to below one
<LinearLayout
android:id="#+id/item_content_action_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/_white"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="7">
<ImageButton
android:id="#+id/item_content_back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_weight="2"
android:background="#drawable/chemist" />
<TextView
android:id="#+id/item_content_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="5"
android:autoText="false"
android:gravity="center"
android:maxLines="2"
android:singleLine="true"
android:text="Title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/Black"
android:textStyle="bold" />
</LinearLayout>
Change Your RelativeLayout to LinearLayout and use android:layout_weight attribute of layout to do this.
<LinearLayout
android:id="#+id/item_content_action_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/_white"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="1"
>
<ImageButton
android:id="#+id/item_content_back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:background="#drawable/chemist" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Title"
android:textColor="#color/colorWhite"
android:textAlignment="center"
android:singleLine="true"
android:layout_gravity="center_vertical"
android:textStyle="bold"
android:gravity="center"
android:layout_weight="1"
android:autoText="false"/>
</LinearLayout>
Make the layout_gravity of the textview item_content_title as "center_horizontal".
And add android:layout_toLeftOf="#+id/item_content_title" under the ImageButton item_content_back_button.
Hope it was what you wanted.
Your Action bar layout has to be like this-
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/item_content_action_bar_layout"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#color/colorBlue"
android:padding="10dp">
<ImageButton
android:layout_width="120dp"
android:layout_height="45dp"
android:id="#+id/item_content_back_button"
android:background="#drawable/back_button_selector"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dp" />
<TextView
android:toRightOf="#id/item_content_back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Title"
android:textColor="#color/colorWhite"
android:textAlignment="center"
android:singleLine="true"
android:layout_gravity="center_vertical"
android:textStyle="bold"
android:autoText="false"
android:layout_centerInParent="true" />
</RelativeLayout>
Related
I've created a preference UI but the thing is I can't let the bottommost child view to be displayed on the device. It keeps discarding the bottommost view. Though this query is similar to one I found in the query list yet the problem I'm facing left me with no debugging ways or I'm missing some serious property.
My code is:
The Bottom TextView which I finally wrapped inside a relativeView is the part which is discarded.
To ,y wonder I changed to LinearLayout from Relative built I guess It might have some issues as well..
But the most important query is that it doesn't scroll till the end of the Activity.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Preferences">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#color/colorPrimary"
android:id="#+id/header"
enter code here
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/back_key"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/text_prefer"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:text="#string/activity_name"
android:textColor="#color/white"
android:textStyle="bold"
android:textSize="18sp"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/wrapper_scroll"
android:layout_below="#id/header"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scroll_horizontal"
android:fillViewport="true"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginLeft="11dp"
android:layout_marginRight="11dp"
android:id="#+id/rel_scroll"
android:layout_marginBottom="10dp"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:background="#drawable/rounded_back_for_layout"
android:id="#+id/rel_age_layout"
android:layout_marginBottom="5dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="18dp"
android:id="#+id/age_text"
android:text="#string/age"
android:textSize="14sp"
android:textStyle="bold"
android:textColor="#color/magenta_brown"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="18dp"
android:layout_alignParentRight="true"
android:text="18-26"
android:textStyle="bold"
android:textSize="14sp"
android:textColor="#color/black"
/>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/text_age_pref"
android:layout_below="#id/rel_age_layout"
android:text="#string/age_prefer"
android:textSize="10.5sp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:layout_below="#id/rel_age_layout"
android:background="#drawable/rounded_back_for_layout"
android:id="#+id/rel_interest_layout"
android:layout_marginBottom="5dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:id="#+id/interested_in_text"
android:text="#string/interested_in"
android:textSize="14sp"
android:textStyle="bold"
android:textColor="#color/magenta_brown"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="18dp"
android:layout_below="#id/interested_in_text"
android:text="#string/men"
android:textSize="14sp"
android:textColor="#color/black"
android:id="#+id/men"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="18dp"
android:layout_below="#id/men"
android:layout_marginTop="10dp"
android:text="#string/women"
android:textSize="14sp"
android:textColor="#color/black"
android:layout_marginBottom="10dp"
/>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/interested_pref"
android:layout_below="#id/rel_interest_layout"
android:text="#string/interested_prefer"
android:textSize="10.5sp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="38dp"
android:layout_below="#id/rel_interest_layout"
android:background="#drawable/rounded_back_for_layout"
android:id="#+id/rel_alerts_layout"
android:layout_marginBottom="5dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="18dp"
android:id="#+id/alerts_mode"
android:text="#string/alerts"
android:textSize="14sp"
android:textStyle="bold"
android:textColor="#color/magenta_brown"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="18dp"
android:layout_below="#id/alerts_mode"
android:text="#string/sound"
android:textSize="14sp"
android:layout_marginBottom="14dp"
android:textColor="#color/black"
/>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sound_prefer"
android:layout_below="#id/rel_alerts_layout"
android:textSize="10.5sp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:layout_marginBottom="5dp"
android:layout_below="#id/rel_alerts_layout"
android:background="#drawable/rounded_back_for_layout"
android:id="#+id/rel_matchmaker_layout"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="18dp"
android:id="#+id/matchmaker_text"
android:text="#string/matchmaker"
android:textSize="14sp"
android:textStyle="bold"
android:textColor="#color/magenta_brown"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="18dp"
android:layout_below="#id/matchmaker_text"
android:text="#string/hide_my_prof"
android:textSize="14sp"
android:textColor="#color/black"
android:layout_marginBottom="10dp"
/>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/matchmaker_prefer"
android:text="#string/matchmaker_prefer"
android:layout_below="#id/rel_matchmaker_layout"
android:textSize="12sp"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="38dp"
android:layout_below="#id/rel_matchmaker_layout"
android:background="#drawable/rounded_back_for_layout"
android:id="#+id/rel_whitelist_layout"
android:layout_marginBottom="10dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="18dp"
android:id="#+id/whitelist_text"
android:text="#string/whitelist"
android:textSize="14sp"
android:textStyle="bold"
android:textColor="#color/magenta_brown"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="18dp"
android:layout_alignParentRight="true"
android:text="#string/go"
android:padding="10dp"
android:background="#drawable/edittext_rectangle_border"
android:textStyle="bold"
android:textSize="14sp"
android:textColor="#color/black"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/rel_whitelist_layout"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10.5sp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:text="#string/whitelist_prefer"
/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
</RelativeLayout>
Here's the screenshot:
Try changing the height of the ScrollView from match_parent to wrap_content:
<ScrollView
...
android:layout_height="wrap_content"
... >
I tried your xml and this worked.
Add this to your last TextView
android:layout_margin="18dp"
Your last element will be:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/rel_whitelist_layout">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10.5sp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:layout_margin="18dp"
android:text="#string/whitelist_prefer"/>
</RelativeLayout>
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.
I have item_list.xml of ListView in side of Activity
Layout shown perfect in Graphical Layout
here put item_list.xml
<?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"
android:background="#5F8295" >
<LinearLayout
android:id="#+id/imageview"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:orientation="vertical" >
<ImageView
android:id="#+id/mImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/android_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/compliance"
android:layout_toRightOf="#+id/imageview"
android:orientation="vertical" >
<TextView
android:id="#+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:singleLine="true"
android:text="TITLE"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#fff"
android:textSize="30sp" />
<TextView
android:id="#+id/txtNoofTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:singleLine="true"
android:text="Text"
android:textColor="#fff"
android:textSize="18sp" />
<TextView
android:id="#+id/txtDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:singleLine="true"
android:text="Other Details for User"
android:textColor="#fff"
android:textSize="18sp" />
<TextView
android:id="#+id/txtExtraDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:singleLine="true"
android:text="Extra Description"
android:textColor="#fff"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/compliance"
android:layout_width="10dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:background="#FF0000"
android:gravity="center_vertical"
android:orientation="horizontal" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/empty" // transparent png image 10x10
/>
</LinearLayout>
</RelativeLayout>
It shown in screen as per below image
I want output as per below image
I dont understand why my color layout not showing its height = "match_parent"
change your layout to some thing like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rightBg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF0000" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:background="#5F8295" >
<LinearLayout
android:id="#+id/imageview"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:orientation="vertical" >
<ImageView
android:id="#+id/mImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/compliance"
android:layout_toRightOf="#+id/imageview"
android:orientation="vertical" >
<TextView
android:id="#+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:singleLine="true"
android:text="TITLE"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#fff"
android:textSize="30sp" />
<TextView
android:id="#+id/txtNoofTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:singleLine="true"
android:text="Text"
android:textColor="#fff"
android:textSize="18sp" />
<TextView
android:id="#+id/txtDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:singleLine="true"
android:text="Other Details for User"
android:textColor="#fff"
android:textSize="18sp" />
<TextView
android:id="#+id/txtExtraDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:singleLine="true"
android:text="Extra Description"
android:textColor="#fff"
android:textSize="18sp" />
</LinearLayout>
</RelativeLayout>
you need to change background color of rightBg id in your getView() method
result:
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>
I am trying to create the following layout in android.
I am unable to achieve the layout as shown in the image.Please ignore the image on the extreme left.
<LinearLayout
android:id="#+id/ll_groups_list_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_weight="1.0"
android:background="#drawable/normal_white_bg"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/groups_list_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="Group name"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/groups_list_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:text="Group Description may come for two lines" />
</LinearLayout>
<ImageView
android:id="#+id/groups_list_image"
android:layout_width="70dp"
android:layout_height="70dp"
android:padding="3dip"
android:src="#drawable/logo" />
this may helpful to you,
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="2dp" >
<ImageView
android:id="#+id/image"
android:layout_width="120dp"
android:layout_height="120dp"
android:contentDescription="#string/news" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#+id/arrow"
android:layout_toRightOf="#+id/thumb"
android:orientation="vertical" >
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:text="#string/text1"
android:textSize="25dp"
android:textStyle="bold" />
<TextView
android:id="#+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginTop="25dp"
android:padding="2dp"
android:paddingTop="20dp"
android:text="#string/text2"
android:textColor="#7F7F7F"
android:textSize="10sp" />
</RelativeLayout>
<ImageView
android:id="#+id/textImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:src="#drawable/image_source" />
</RelativeLayout>
Try this way,hope this will help you to solve your problem.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFF00"
android:padding="5dp">
<LinearLayout
android:id="#+id/ll_groups_list_text"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:orientation="vertical"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:gravity="center_vertical"
android:padding="5dp">
<TextView
android:id="#+id/groups_list_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="Group name"
android:textColor="#000000"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/groups_list_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:textColor="#000000"
android:layout_marginTop="5dp"
android:text="Group Description may come for two lines" />
</LinearLayout>
<ImageView
android:id="#+id/groups_list_image"
android:layout_width="70dp"
android:layout_height="70dp"
android:padding="3dip"
android:background="#FFFFFF"
android:src="#drawable/ic_launcher" />
</LinearLayout>
Please use this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFF00"
android:padding="2dp" >
<RelativeLayout
android:id="#+id/ll_groups_list_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#FFFFFF"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/imageView1"
android:text="Text1"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView1"
android:layout_alignParentLeft="true"
android:text="Text 2"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
</LinearLayout>