I am facing android design issue , I can't understand why it happened it is weird.
My layout code :
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<RelativeLayout
android:id="#+id/outgoing_layout_bubble"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="60dp"
android:layout_marginRight="8dp"
android:background="#drawable/chatrectbg"
android:padding="10dp"
android:visibility="visible">
<TextView
android:id="#+id/message"
style="#style/chat_text_message_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toStartOf="#+id/time"
android:autoLink="web"
android:paddingRight="10dp"
android:text="#{chat.messageText}"
android:textColor="#android:color/white"
android:textStyle="bold" />
<TextView
android:id="#id/time"
style="#style/chat_timings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="4dp"
android:padding="5dp"
android:paddingRight="10dp"
android:text="#{chat.messageTime}"
android:textColor="#android:color/white"
android:textStyle="bold" />
</RelativeLayout>
</RelativeLayout>
preview of this code is as below :
I want background color change wrapping text, but it doesn't.
I can't understand what I am doing wrong?
You can try like 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="wrap_content"
android:padding="10dp"
android:layout_gravity="end"
android:gravity="end"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#555"
android:padding="10dp"
android:gravity="end|center_vertical"
android:layout_gravity="right"
android:orientation="vertical">
<TextView
android:id="#+id/message"
style="#style/chat_text_message_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:text="Message "
android:textColor="#android:color/white"
android:textStyle="bold" />
<TextView
android:id="#id/time"
style="#style/chat_timings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/message"
android:padding="5dp"
android:gravity="right"
android:text="Time"
android:textColor="#android:color/white"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
Related
I have been working on this XML code and got error stating duplicate error attribute I went through the code but couldn't find the solution.
Here is my XML Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/wf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:paddingTop="10dp"
android:text="WIMBELDON FINALS"
android:textSize="25sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="60dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
tools:context="com.example.vidit.project2.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="20dp"
android:text="roger federer"
android:textAllCaps="true"
android:textSize="15sp" />
<TextView
android:id="#+id/r"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="20dp"
android:text="0"
android:textSize="25sp" />
<Button
android:id="#+id/score1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="scorer"
android:text="POINT" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="20dp"
android:text="Sets Won: "
android:textAllCaps="true"
android:textSize="20dp" />
<TextView
android:id="#+id/setr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="10dp"
android:text="0"
android:textSize="25dp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
tools:context="com.example.vidit.project2.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="20dp"
android:text="djokovic"
android:textAllCaps="true"
android:textSize="15sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="20dp"
android:text="0"
android:textSize="25sp" />
<Button
android:id="#+id/score2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="POINT" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="20dp"
android:text="Sets Won: "
android:textAllCaps="true"
android:textSize="20dp" />
<TextView
android:id="#+id/setd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="10dp"
android:text="0"
android:textSize="25dp" />
</LinearLayout>
</LinearLayout>
<Button
android:id="#+id/reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:onClick="reset"
android:text="RESET" />
</RelativeLayout>
The error being Showed :Error parsing XMl duplicate Attribute.
Please Guide me.
Thank you
Just off the top of my head I see "xmlns:android" appearing twice in your root RelativeLayout; try removing one of those and seeing if that does the trick!
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>
I have to align one TextView in the middle of a ImageView-->ImageButton, I know that is not difficult but my problems come because the image can have variable size , so when I got different images, the text view moves around, and don't stay aligned horizontally in the middle of the image.
A image can help to my explanation:
At this moment I set the image and text like this:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar_circuitomedico"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:elevation="12dp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="fill_parent">
<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_marginLeft="20dp"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="#string/professional"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/circ_profesionall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView1"
android:layout_alignBottom="#+id/textView1"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_toRightOf="#+id/textView1"
android:layout_toEndOf="#+id/textView1"
android:text="#string/medico_test"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_alignStart="#+id/textView1"
android:layout_below="#+id/textView1"
android:layout_marginTop="12dp"
android:text="#string/medical_service"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="#+id/circ_spin_tipus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView3"
android:layout_alignStart="#+id/textView3"
android:layout_marginTop="12dp"
android:layout_below="#+id/textView3" />
<Spinner
android:id="#+id/circ_spin_tipocons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/circ_spin_tipus"
android:layout_alignStart="#+id/circ_spin_tipus"
android:layout_marginTop="12dp"
android:layout_below="#+id/circ_spin_tipus" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/circ_spin_tipocons"
android:layout_alignStart="#+id/circ_spin_tipocons"
android:layout_below="#+id/circ_spin_tipocons"
android:text="#string/circuit_curesnafres"
android:layout_marginTop="12dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView4"
android:layout_alignStart="#+id/textView4"
android:layout_below="#+id/textView4"
android:layout_marginTop="12dp"
android:text="#string/circuit_nhc"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="#+id/circ_spin_tipolesion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView5"
android:layout_alignStart="#+id/textView5"
android:layout_below="#+id/textView5"
android:layout_marginTop="12dp" />
<Spinner
android:id="#+id/circ_spin_local"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/circ_spin_tipolesion"
android:layout_alignStart="#+id/circ_spin_tipolesion"
android:layout_below="#+id/circ_spin_tipolesion"
android:layout_marginTop="12dp" />
<Spinner
android:id="#+id/circ_spin_escalas"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/circ_spin_local"
android:layout_alignStart="#+id/circ_spin_local"
android:layout_below="#+id/circ_spin_local"
android:layout_marginTop="12dp" />
<EditText
android:id="#+id/circ_box_descrip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/circ_spin_escalas"
android:layout_alignStart="#+id/circ_spin_escalas"
android:layout_below="#+id/circ_spin_escalas"
android:layout_marginTop="12dp"
android:layout_marginRight="20dp"
android:layout_marginEnd="20dp"
android:ems="12"
android:inputType="textMultiLine" >
</EditText>
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/circ_box_descrip"
android:layout_alignStart="#+id/circ_box_descrip"
android:layout_below="#+id/circ_box_descrip"
android:layout_marginTop="12dp"
android:src="#drawable/button_picture" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageButton1"
android:layout_marginTop="30dp"
android:layout_toRightOf="#+id/textView1"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
This is Best as per your Requirement :-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/img"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="im in Center"
android:textStyle="bold"
android:textSize="30sp"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
Thank you and have a best Programming..
Try to replace your textview which you want to align with this:
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageButton1"
android:layout_alignTop="#+id/imageButton1"
android:layout_toRightOf="#+id/imageButton1"
android:gravity="center"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
This will make your text view aligned with your imageview and text will be shown with center gravity.
Problem is that if your image will be less than the text size or text lines .
Try this-->
<RelativeLayout
android:id="#+id/relative"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/your_image" />
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#id/image"
android:layout_alignLeft="#id/image"
android:layout_alignRight="#id/image"
android:layout_alignTop="#id/image"
android:gravity="center"
android:maxLines="5"
android:textColor="#000000"
android:textSize="8dp"
android:textStyle="bold" />
</RelativeLayout>
Try this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="100">
<ImageView
android:id="#+id/image1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="50"
android:src="#drawable/clock_number"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="50"
android:layout_marginStart="12dp"
android:text="Hello World!" />
</LinearLayout>
Good day guys. I seriously need someone help to adjust my xml layout.
The above image shows the ListView, where it supposes to look like :
Image on the left, text on the right
Claims Type : Project
Amount : 100
Description : Trainning
xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="start"
android:background="#android:color/white"
android:padding="12dp">
<ImageView
android:id="#+id/image"
android:layout_width="80dp"
android:layout_height="70dp"
android:layout_centerVertical="true"
android:layout_gravity="left"/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/image"
android:layout_marginRight="4dp"
android:layout_centerVertical="true"
android:paddingLeft="6dp"
android:orientation="vertical">
<TextView
android:id="#+id/Claimtype"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="Claims Type : "
android:maxLines="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/type"
android:layout_toRightOf="#+id/Claimtype"/>
<TextView
android:id="#+id/Amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="#android:color/secondary_text_dark_nodisable"
android:text="Amount : "
android:maxLines="1"
android:ellipsize="end"
android:layout_below="#+id/Claimtype" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/amount"
android:layout_toRightOf="#+id/Amount"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="#android:color/secondary_text_dark_nodisable"
android:text="Description : "
android:maxLines="1"
android:layout_below="#+id/Amount" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/description"
android:layout_toRightOf="#+id/Description"/>
</RelativeLayout>
</RelativeLayout>
Thanks a lot ..
Simply you just need a LinearLayout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="1">
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:id="#+id/imageView"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.4"
android:id="#+id/textView"/>
</LinearLayout>
And create String like:
Claims Type : "yourType" + "\n"
Amount : 100 + "\n"
Description : Trainning + "\n"
to set for your TextView
You can try that, i do it, fast so it's not really beautiful but it's what you want (i think). Try to not put solid value.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="start"
android:background="#android:color/white"
android:padding="12dp">
<ImageView
android:id="#+id/image"
android:layout_width="80dp"
android:layout_height="70dp"
android:layout_centerVertical="true"
android:layout_gravity="left"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/image"
android:layout_centerVertical="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/Claimtype"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="Claims Type : "
android:maxLines="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/type"
android:layout_toRightOf="#+id/Claimtype"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/image"
android:layout_centerVertical="true"
android:orientation="horizontal">
<TextView
android:id="#+id/Amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="#android:color/secondary_text_dark_nodisable"
android:text="Amount : "
android:maxLines="1"
android:ellipsize="end"
android:layout_below="#+id/Claimtype" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/amount"
android:layout_toRightOf="#+id/Amount"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/image"
android:layout_centerVertical="true"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="#android:color/secondary_text_dark_nodisable"
android:text="Description : "
android:maxLines="1"
android:layout_below="#+id/Amount" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/description"
android:layout_toRightOf="#+id/Description"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
For performance purposes, do not embed RelativeLayouts one into another. Since you only have two child in the parent RelativeLayout, you can use a LinearLayout instead.
Now regarding your issue :
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/amount"
android:layout_toRightOf="#+id/Amount"/>
layout_toRightOf means the TextView will be place at the right of the indicated View, only horizontally. You need to add a layout_below attribute also.
try this, I have done it into my workspace.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mytextview="http://schemas.android.com/apk/res/com.bne"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/rlMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp" >
<ImageView
android:id="#+id/imgCover"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#drawable/ic_launcher" />
<RelativeLayout
android:id="#+id/rlHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="2dp"
android:layout_toLeftOf="#+id/imgArrow"
android:layout_toRightOf="#+id/imgCover" >
<TextView
android:id="#+id/txtCoverHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/black"
android:textSize="14sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rlCT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/imgCover" >
<TextView
android:id="#+id/txtCT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/txtDateTime"
android:gravity="center"
android:text="Claims Type :"
android:textColor="#android:color/black"
android:textSize="10sp" />
<TextView
android:id="#+id/txtOutCT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/txtCT"
android:gravity="center"
android:text="Project"
android:textColor="#android:color/black"
android:textSize="10sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rlAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rlCT"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/imgCover" >
<TextView
android:id="#+id/txtAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/txtDateTime"
android:gravity="center"
android:text="Amount :"
android:textColor="#android:color/black"
android:textSize="10sp" />
<TextView
android:id="#+id/txtOutAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/txtAmount"
android:gravity="center"
android:text="100"
android:textColor="#android:color/black"
android:textSize="10sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rlTraining"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rlAmount"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/imgCover" >
<TextView
android:id="#+id/txtTraining"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/txtDateTime"
android:gravity="center"
android:text="Description :"
android:textColor="#android:color/black"
android:textSize="10sp" />
<TextView
android:id="#+id/txtOutTraining"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/txtTraining"
android:gravity="center"
android:text="Trainning"
android:textColor="#android:color/black"
android:textSize="10sp" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
Use this and let me know if some issue
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="start"
android:background="#android:color/white"
android:padding="12dp">
<ImageView
android:id="#+id/image"
android:layout_width="80dp"
android:layout_height="70dp"
android:layout_centerVertical="true"
android:layout_gravity="left"/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/image"
android:layout_centerVertical="true"
android:paddingLeft="6dp"
android:orientation="vertical"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true">
<LinearLayout
android:id="#+id/ll1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/Claimtype"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="Claims Type : "
android:singleLine="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/type"
android:text="dsjfhjh"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/ll2"
android:layout_below="#+id/ll1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/Amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="#android:color/secondary_text_dark_nodisable"
android:text="Amount : "
android:maxLines="1"
android:ellipsize="end" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/amount"
android:text="dsjfhjsdkh" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll3"
android:layout_below="#+id/ll2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="#android:color/secondary_text_dark_nodisable"
android:text="Description : "
android:maxLines="1"
android:layout_below="#+id/Amount" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/description"
android:text="jksdhfj"
android:layout_toRightOf="#+id/Description"/>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
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>