RelativeLayout for ListView item - android

First of all, if this question is a copy, I am sorry!!!
I have this layout for a ListView item and it doesn't work ok.
I want a center line separator, On the left of the line one number and another one on the right.
<?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"
android:padding="10dp">
<TextView
android:id="#+id/separador"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text=" - " />
<TextView
android:id="#+id/local_ptos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/separador"
android:layout_centerVertical="true"
android:text="188"/>
<TextView
android:id="#+id/visitante_ptos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/separador"
android:layout_centerVertical="true"
android:text="200"/>
</RelativeLayout>
If I change this line:
<?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"
android:padding="10dp">
<TextView
android:id="#+id/separador"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text=" - " />
<TextView
android:id="#+id/local_ptos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/separador"
android:layout_centerVertical="true"
android:text="188"/>
<TextView
android:id="#+id/visitante_ptos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="200"/>
</RelativeLayout>
I have this result:
image
Why??
Thanks!!!
I really want this: image
I get this with this code:
<?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"
android:padding="10dp">
<TextView
android:id="#+id/local_ptos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:paddingRight="50dp"
android:textStyle="bold"
android:textSize="20sp"
android:text="100"/>
<TextView
android:id="#+id/visitante_ptos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:paddingLeft="50dp"
android:textStyle="bold"
android:textSize="20sp"
android:text="200"/>
<TextView
android:id="#+id/separador"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignBottom="#id/local_ptos"
android:text=" - " />
<TextView
android:id="#+id/local_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignBottom="#id/local_ptos"/>
<TextView
android:id="#+id/visitante_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignBottom="#id/visitante_ptos"/>
</RelativeLayout>
But I don't like this code and I want the separator line vertical centered with numbers.
Sorry my English

You needed following attributes: android:layout_toLeftOf and android:layout_toRightOf.
<?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"
android:padding="10dp" >
<TextView
android:id="#+id/separador"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text=" - " />
<TextView
android:id="#+id/local_ptos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/separador"
android:layout_centerVertical="true"
android:text="188" />
<TextView
android:id="#+id/visitante_ptos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/separador"
android:text="200" />
</RelativeLayout>

Hope i have understood your question here is your xml code:
<?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"
android:padding="10dp" >
<TextView
android:id="#+id/separador"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text=" - " />
<TextView
android:id="#+id/local_ptos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/separador"
android:layout_centerVertical="true"
android:text="188" />
<TextView
android:id="#+id/visitante_ptos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/separador"
android:layout_centerVertical="true"
android:text="200" />
<TextView
android:id="#+id/visitante_ptos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:textStyle="bold"
android:text="JPS" />
<TextView
android:id="#+id/visitante_ptos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:textStyle="bold"
android:text="CABA" />
</RelativeLayout>

Related

Xml is not Working when change the place of textview in linear layout in Android

I have a working android app which has a page that uses this xml.
<?xml version="1.0" encoding = "utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your total is 0"
android:layout_gravity="center"
android:textSize="45dp"
android:id="#+id/Rapor"
/>
<Button
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="blabla"
android:layout_gravity="center"
android:textSize="20dp"
android:id="#+id/blabla"
/>
<Button
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="blaa"
android:layout_gravity="center"
android:textSize="20dp"
android:id="#+id/blaa"
/>
<Button
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="Rapor"
android:layout_gravity="center"
android:textSize="20dp"
android:id="#+id/Report"
/>
</LinearLayout>
My problem is the following. Right now my textview is on top of three buttons. I want to show this textview below the buttons. But when I cut the textview part and paste it after the third(last)button my app crashes. How can I put my textview below the buttons and why does my program crash?
Use this
<?xml version="1.0" encoding = "utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="blabla"
android:layout_gravity="center"
android:textSize="20dp"
android:id="#+id/blabla"
/>
<Button
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="blaa"
android:layout_gravity="center"
android:textSize="20dp"
android:id="#+id/blaa"
/>
<Button
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="Rapor"
android:layout_gravity="center"
android:textSize="20dp"
android:id="#+id/Report"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your total is 0"
android:textSize="45dp"
android:id="#+id/Rapor"
android:layout_gravity="center"
/>
</LinearLayout>
Or Use this :
<?xml version="1.0" encoding = "utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal">
<Button
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="blabla"
android:layout_gravity="center"
android:textSize="20dp"
android:id="#+id/blabla"
/>
<Button
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="blaa"
android:layout_gravity="center"
android:textSize="20dp"
android:layout_below="#+id/blabla"
android:id="#+id/blaa"
/>
<Button
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="Rapor"
android:layout_gravity="center"
android:textSize="20dp"
android:layout_below="#+id/blaa"
android:id="#+id/Report"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your total is 0"
android:textSize="45dp"
android:layout_below="#+id/Report"
android:id="#+id/Rapor"
android:layout_gravity="center"
/>
</RelativeLayout>
Output :

Imagebuttons won't align on the right next to eachother

I'm dynamically injecting rows in a container of a fragment.
But I just can't seem to get the three image buttons aligned to the right, next to each other.
Anyone an idea?
Fragment layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scenesScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/switchLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/scenesTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/switch_title"
android:text="#string/title_switches" />
<LinearLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="vertical">
</LinearLayout>
<TextView
android:id="#+id/statusText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"/>
</LinearLayout>
</ScrollView>
My row layout:
<?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="wrap_content"
android:paddingBottom="10dp">
<TextView
android:id="#+id/switch_name"
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/switch_row_name"
android:text="Switch name"/>
<TextView
android:id="#+id/switch_lastSeen"
android:layout_below="#id/switch_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/switch_row_lastSeen"
android:text="#string/last_seen"/>
<TextView
android:id="#+id/switch_status"
android:layout_below="#id/switch_lastSeen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/switch_row_level"
android:text="#string/status"/>
<ImageButton
android:id="#+id/switch_button_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_arrow_up"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
<ImageButton
android:id="#+id/switch_button_stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_stop"
android:layout_toLeftOf="#+id/switch_button_down"
android:layout_toStartOf="#+id/switch_button_down"
android:layout_centerVertical="true" />
<ImageButton
android:id="#+id/switch_button_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_arrow_down"
android:layout_toLeftOf="#+id/switch_button_up"
android:layout_toStartOf="#+id/switch_button_up"
android:layout_centerVertical="true" />
</RelativeLayout>
How the row looks on my phone (the same on a API 19 AVD):
How Android Studio, when designing, shows the row:
try this
<?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="wrap_content"
android:paddingBottom="10dp">
<TextView
android:id="#+id/switch_name"
style="#style/switch_row_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="Switch name" />
<TextView
android:id="#+id/switch_lastSeen"
style="#style/switch_row_lastSeen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/switch_name"
android:text="#string/last_seen" />
<TextView
android:id="#+id/switch_status"
style="#style/switch_row_level"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/switch_lastSeen"
android:text="#string/status" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:orientation="horizontal">
<ImageButton
android:id="#+id/switch_button_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_arrow_up" />
<ImageButton
android:id="#+id/switch_button_stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_stop" />
<ImageButton
android:id="#+id/switch_button_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_arrow_down" />
</LinearLayout>
</RelativeLayout>

How to put an element on the right of some rows in RelativeLayout?

i created this layout for my list rows:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:background="#drawable/press_event" >
<LinearLayout
android:id="#+id/viewNameM"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/orange_button_pressed" >
<TextView
android:id="#+id/nameUser"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#f6911e"
android:textStyle="bold" />
</LinearLayout>
<RelativeLayout
android:id="#+id/viewDetails1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/viewNameM"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" >
<ImageView
android:id="#+id/arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/catUser"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/catUser"
android:contentDescription="#string/arrowS"
android:src="#drawable/arrow" />
<TextView
android:id="#+id/catUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginBottom="3dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#4a4c4d" />
<RatingBar
android:id="#+id/ratingUser"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/arrow"
android:layout_marginRight="20dp"
android:layout_marginBottom="3dp"
android:layout_alignBottom="#+id/catUser"
android:indeterminate="false"
android:isIndicator="true"
android:numStars="#integer/five"
android:stepSize="0.1" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/viewDetails2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/viewDetails1"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" >
<TextView
android:id="#+id/cityUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textStyle="bold"
android:layout_marginBottom="3dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#4a4c4d" />
<TextView
android:id="#+id/distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
</RelativeLayout>
Here is the output:
I would like to keep the arrow on the right of the rows, but i would to set it in the middle, like this:
I make several tries, but i cannot reach my goal. How to do that?
Thank you in advance.
Just do it like you would in real life:
Place caret on the right.
Place rating on the left of the caret, below separating line.
Place distance to the left of the caret, below rating.
...
<?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"
android:background="#ffffff" >
<LinearLayout
android:id="#+id/viewNameM"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#cccccc" >
<TextView
android:id="#+id/nameUser"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#f6911e"
android:textStyle="bold" />
</LinearLayout>
<RelativeLayout
android:id="#+id/viewDetails1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/viewNameM"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" >
<ImageView
android:id="#+id/arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="#drawable/chevron" />
<TextView
android:id="#+id/catUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Hotel"
android:layout_marginBottom="3dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#4a4c4d" />
<RatingBar
android:id="#+id/ratingUser"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/arrow"
android:layout_marginBottom="3dp"
android:layout_alignBottom="#+id/catUser"
android:indeterminate="false"
android:isIndicator="true"
android:numStars="5"
android:stepSize="0.1" />
<TextView
android:id="#+id/cityUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#id/catUser"
android:textStyle="bold"
android:text="Roma"
android:layout_marginBottom="3dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#4a4c4d" />
<TextView
android:id="#+id/distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/arrow"
android:layout_below="#id/ratingUser"
android:textColor="#4a4c4d"
android:text="22km"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
</RelativeLayout>
This is looks like you want.
Create layout of this type using Layout weight in LinnerLayout

How to center align TextView below another TextView in a ListView

Currently my XML looks like the following:
What I'm trying to do is have 'Day' (which gets replaced with actual day (e.g. 03, 24)) horizontally centered below month (where in 'Month' also gets replaced with a MMM formatted month string) such that the horizontal center of day matches the horizontal center of month. To the side are some other TextView objects such as the event name and event time.
I based my XML in part off of How to center align a textview below imageview as a title in a List view but day is slightly too far to the right and I'm not quite sure how to remedy the issue despite fiddling around with attributes from the RelativeLayout docs.
http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html
events_info.xml (layout for ListView objects):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/eventsRelLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="6dip">
<TextView
android:id="#+id/month"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Month" />
<TextView
android:id="#+id/day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/month"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:singleLine="true"
android:text="Day" />
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/month"
android:paddingLeft="10dp"
android:paddingRight="0dp"
android:text="Name" />
<TextView
android:id="#+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/name"
android:layout_toRightOf="#id/month"
android:paddingLeft="10dp"
android:paddingRight="0dp"
android:text="Time" />
fragment_event_list.xml (ListView):
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
tools:context="fish.glow.EventFragment">
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
Try this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/rl_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/month"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="month month" />
<TextView
android:id="#+id/day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/month"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="day" />
</RelativeLayout>
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#+id/rl_left"
android:text="name" />
<TextView
android:id="#+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/name"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#+id/rl_left"
android:text="time" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/eventsRelLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="6dip">
<LinearLayout
android:id="#+id/date"
android:orienation="vertical"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/month"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Month" />
<TextView
android:id="#+id/day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/month"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:singleLine="true"
android:text="Day" />
</LinearLayout>
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/date"
android:paddingLeft="10dp"
android:paddingRight="0dp"
android:text="Name" />
<TextView
android:id="#+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/name"
android:layout_toRightOf="#id/date"
android:paddingLeft="10dp"
android:paddingRight="0dp"
android:text="Time" />

ListView Row Height Too Small

Below is an image of a ListView row that is too short. I've tried too many combinations and yield my frustration to StackOverflow.
How can I fix this and show the whole row? Here is the XML for the item.
<?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="fill_parent"
android:weightSum="1">
<LinearLayout android:id="#+id/item_left"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingRight="2dp"
android:paddingLeft="2dp"
android:background="#drawable/item_left"
android:layout_gravity="fill_vertical">
<TextView
android:id="#+id/status_day"
android:layout_gravity="center_vertical"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:textColor="#color/item_left_text"
android:textSize="25sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="2dp"
android:background="#drawable/item_right"
android:layout_weight="1">
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/item_right_text"
android:text="" />
<TextView
android:id="#+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/item_right_text"
android:text="" />
</LinearLayout>
<ImageButton
android:id="#+id/options"
android:background="#drawable/item_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_menu_moreoverflow_normal_holo_light"
/>
</LinearLayout>
Any help is appreciated.
can you use this, set row layout height
android:layout_height="?android:attr/listPreferredItemHeight"
I set the height of the ImageButton to match_parent.
This fixed the issue oddly. Sigh.
your layout should be in such manner for your requirement i have pasted not same as your's layout but related to it check it
<?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="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="60dp" >
<ImageView
android:id="#+id/ivArrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:focusable="false"
android:clickable="false"
android:src="#drawable/arrow" />
<RelativeLayout
android:id="#+id/ivIcon"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:focusable="false"
android:clickable="false"
android:background="#drawable/oddnumbg" >
<TextView
android:id="#+id/tvNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:textColor="#color/ReceiptNoLable"
android:text="No." />
<TextView
android:id="#+id/tvReceiptNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:singleLine="true"
android:layout_below="#+id/tvNo"
android:gravity="center"
android:textColor="#color/ReceiptSavedColor"
android:textSize="18dp"
android:text="1234" />
</RelativeLayout>
<TextView
android:id="#+id/tvSubName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/ivIcon"
android:text="RECEIVED FROM"
android:gravity="center"
android:focusable="false"
android:clickable="false"
android:textColor="#color/ReceiptNoLable"
/>
<TextView
android:id="#+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/ivIcon"
android:layout_below="#+id/tvSubName"
android:text="RECEIPT"
android:layout_marginLeft="15dp"
android:textColor="#color/ReceiptSavedColor"
android:textSize="30dp"
android:focusable="false"
android:layout_toLeftOf="#+id/tvReceiptPrize"
android:clickable="false"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/tvReceiptPrize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/ivArrow"
android:background="#drawable/myreceiptprizebg"
android:gravity="center"
android:singleLine="true"
android:layout_marginRight="5dp"
android:textSize="20dp"
android:textColor="#fff"
android:text="$84.20" />
</RelativeLayout>
</LinearLayout>
just set the height of the outer layout, instead of using fill_parent
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:awesome="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height=50dp <!-- or anything which fits -->

Categories

Resources