relative layout can't wrap and keep stretching - android

i have this layout
i have set the grey box width to wrap_content but it won't wrap instead it just stretched like usual. this is die xml
<?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:padding="10dp"
android:background="#ffffff" >
<ImageView
android:id="#+id/item_image"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#drawable/image_photo" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:padding="5dp"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/item_image"
android:background="#cccccc" >
<TextView
android:id="#+id/item_text_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:textStyle="bold"
android:textSize="20sp"
android:text="Name"
/>
<TextView
android:id="#+id/item_text_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_alignRight="#+id/item_text_1"
android:textSize="14sp"
android:text="Message"
/>
</RelativeLayout>
</RelativeLayout>
just like chat list item in common, you know, the box should wrap the content inside it right?
so how can i achieve this?
thanks!
UPDATE
this is my right aligned chat item box, 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="wrap_content"
android:padding="10dp"
android:background="#ffffff" >
<ImageView
android:id="#+id/item_image"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#drawable/image_photo" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:padding="5dp"
android:orientation="vertical"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/item_image"
android:background="#cccccc" >
<TextView
android:id="#+id/item_text_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:textStyle="bold"
android:textSize="20sp"
android:text="Name"
/>
<TextView
android:id="#+id/item_text_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="right"
android:layout_gravity="right"
android:textSize="14sp"
android:text="Message"
/>
</LinearLayout>
</RelativeLayout>
for the left aligned chat box in case for another user, you just have to remove android:layout_gravity and android:gravity! Thanks!

just remove
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
from
<TextView
android:id="#+id/item_text_1"
...
as you want to align its parent not the view itself

Related

TextView height stretches in parent with gravity right. why?

I am making chat activity and having issues with right chat bubble. As you can see in the image below. TextView stretches height wise. According to my thinking it should be stretching width wise first then if space is full it should stretch height wise. Please suggest me if it is possible with xml or not. I have seen java code solution but i want to find a solution in xml first.
layout.xml
<?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:gravity="right"
android:orientation="horizontal"
android:paddingBottom="10dp"
android:paddingTop="10dp">
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="20" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="80"
android:gravity="right">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:background="#drawable/ic_bubble_sent"
android:gravity="right">
<TextView
android:id="#+id/txt_msg_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="#+id/txt_message_time"
android:layout_toStartOf="#+id/txt_message_time"
android:textSize="16sp"
android:text="Lorem"
android:visibility="visible" />
<TextView
android:id="#+id/txt_message_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txt_msg_content"
android:layout_marginTop="-9dp"
android:text="00:33"
android:textColor="#color/colorAppGray"
android:textSize="12sp"
android:textStyle="normal" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
Replace your two TextView with this,
<TextView
android:id="#+id/txt_msg_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:text="Lorem"
android:visibility="visible"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/txt_message_time"
android:layout_toStartOf="#+id/txt_message_time"
android:layout_marginRight="32dp"
android:layout_marginEnd="32dp" />
<TextView
android:id="#+id/txt_message_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00:33"
android:textSize="12sp"
android:textStyle="normal"
android:layout_alignBaseline="#+id/txt_msg_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
I removed all unnecessary alignments from first TextView.
UPDATE
The overall layout looks like,
<?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:paddingBottom="10dp"
android:paddingTop="10dp">
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="20" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="80"
android:gravity="right">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
>
<TextView
android:id="#+id/txt_msg_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:text="Lorem"
android:visibility="visible"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/txt_message_time"
android:layout_toStartOf="#+id/txt_message_time"
android:layout_marginRight="32dp"
android:layout_marginEnd="32dp" />
<TextView
android:id="#+id/txt_message_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00:33"
android:textSize="12sp"
android:textStyle="normal"
android:layout_alignBaseline="#+id/txt_msg_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
Note : I removed your background for testing.

relative layout gravity center not aligning correctly

I'm trying to center the chilldren of my relative layout in the center of my screen but it's acting like it's aligned to the top of the parent and I can't figure out why.
my .XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:background="#f70909">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView2"
android:adjustViewBounds="true"
android:src="#drawable/dice"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/textMessage"
android:layout_centerHorizontal="true"
android:layout_below="#+id/imageView2" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editUserSplash"
android:hint="Username"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_below="#+id/textMessage" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editPasswordSplash"
android:hint="Password"
android:layout_centerHorizontal="true"
android:gravity="center"
android:layout_below="#+id/editUserSplash" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:id="#+id/btnSplash"
android:layout_centerHorizontal="true"
android:layout_below="#+id/editPasswordSplash" />
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/prgSplash"
style="#android:style/Widget.DeviceDefault.ProgressBar.Large"
android:layout_centerHorizontal="true"
android:indeterminate="true"
android:layout_below="#+id/btnSplash" />
</RelativeLayout>
I've tried making the parent a relativelayout without success and it won't align to the bottom either. Initially I thought the layout wasn't filling the whole screen but since its height and width are match_parent I don't think that's the problem. in android studio it is displaying correctly though so I must be missing something small.
I also tried using the gravity and layoutgravity parameters and a combination of the two but without success
Edit: I need the views to stay in the same formation relative to each other but centered in the screen vertically.
Edit 2:I set the background of the RelativeLayout to red and got this: So the relativelayout isn't filling my screen.
Edit 3:
Edit 4:
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="match_parent"
android:background="#f70909">
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView2"
android:adjustViewBounds="true"
android:src="#drawable/dice"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/textMessage"
android:layout_centerHorizontal="true"
android:layout_below="#+id/imageView2" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editUserSplash"
android:hint="Username"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_below="#+id/textMessage" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editPasswordSplash"
android:hint="Password"
android:layout_centerHorizontal="true"
android:gravity="center"
android:layout_below="#+id/editUserSplash" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:id="#+id/btnSplash"
android:layout_centerHorizontal="true"
android:layout_below="#+id/editPasswordSplash" />
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/prgSplash"
style="#android:style/Widget.DeviceDefault.ProgressBar.Large"
android:layout_centerHorizontal="true"
android:indeterminate="true"
android:layout_below="#+id/btnSplash" />
</RelativeLayout>
</RelativeLayout>
Try something like 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="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView2"
android:adjustViewBounds="true"
android:layout_centerInParent="true"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:layout_centerInParent="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/textMessage" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editUserSplash"
android:hint="Username"
android:gravity="center" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editPasswordSplash"
android:hint="Password"
android:gravity="center" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:id="#+id/btnSplash" />
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/prgSplash"
style="#android:style/Widget.DeviceDefault.ProgressBar.Large"
android:indeterminate="true" />
</LinearLayout>
</RelativeLayout>
UPDATE:
If setting the xml in an AlertDialog, it's possible that there is a space allotted at the bottom. I google and found this alert_dialog.xml for reference. It seems that there is a buttonPanel at the bottom with a minimum height of 54dip.
<LinearLayout android:id="#+id/buttonPanel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="54dip"
android:orientation="vertical" >
<LinearLayout
style="?android:attr/buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="4dip"
android:paddingStart="2dip"
android:paddingEnd="2dip"
android:measureWithLargestChild="true">
<LinearLayout android:id="#+id/leftSpacer"
android:layout_weight="0.25"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone" />
<Button android:id="#+id/button1"
android:layout_width="0dip"
android:layout_gravity="start"
android:layout_weight="1"
style="?android:attr/buttonBarButtonStyle"
android:maxLines="2"
android:layout_height="wrap_content" />
<Button android:id="#+id/button3"
android:layout_width="0dip"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
style="?android:attr/buttonBarButtonStyle"
android:maxLines="2"
android:layout_height="wrap_content" />
<Button android:id="#+id/button2"
android:layout_width="0dip"
android:layout_gravity="end"
android:layout_weight="1"
style="?android:attr/buttonBarButtonStyle"
android:maxLines="2"
android:layout_height="wrap_content" />
<LinearLayout android:id="#+id/rightSpacer"
android:layout_width="0dip"
android:layout_weight="0.25"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
I think this may help you
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:gravity="center">
<RelativeLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#+id/textMessage"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editUserSplash"
android:hint="Username"
android:layout_below="#+id/textMessage"
android:gravity="center" />
<EditText
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editPasswordSplash"
android:hint="Password"
android:layout_below="#+id/editUserSplash"
android:gravity="center" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:id="#+id/btnSplash"
android:layout_below="#+id/editPasswordSplash"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Thanks to ank I was able to figure out that the reason why the RelativeLayout didn't fill my screen is that I used it in an alertDialog. So RelativeLayouts parent isn't the screen but the alertDialog. Since an alertDialog wraps its content it doesn't fill the entire screen.

Android RelativeLayout align element on another elements border

Im trying to make a text view to align to the left border of another imageview in a RelativeLayout, but I'm having trouble and I cannot achieve this. Can anyone tell me how can I achieve this?
Here is my current XML layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:orientation="vertical" >
<ImageView
android:id="#+id/main_item_bg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:contentDescription="#string/app_name"
android:scaleType="fitXY" />
<RelativeLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#drawable/blackalha"
android:gravity="center_vertical"
android:orientation="horizontal"
android:weightSum="100" >
<TextView
android:id="#+id/main_item_cont"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/main_item_nmb"
android:paddingLeft="5dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/white" />
<ImageView
android:id="#+id/main_item_ic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#color/app_purple"
android:src="#drawable/bacal" />
<TextView
android:id="#+id/main_item_nmb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/main_item_ic"
android:background="#drawable/saric"
android:gravity="center"
android:textColor="#333333" />
</RelativeLayout>
<TextView
android:id="#+id/main_item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/main_item_bg"
android:layout_margin="5dp"
android:maxWidth="200dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/white" />
</RelativeLayout>
Try this
<?xml version="1.0" encoding="utf-8"?>
<ImageView
android:id="#+id/main_item_bg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:contentDescription="#string/app_name"
android:scaleType="fitXY" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="80dip"
android:gravity="center"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<TextView
android:id="#+id/main_item_cont"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center"
android:paddingLeft="5dp"
android:text="dsgffdufsdfdfsdfdsfsdfsdfdsfdf"
android:inputType="textMultiLine"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/white" />
<ImageView
android:id="#+id/main_item_ic"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dip"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/main_item_cont"
android:background="#android:color/black"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/main_item_nmb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/main_item_cont"
android:layout_toRightOf="#+id/main_item_cont"
android:background="#android:color/white"
android:text="10"
android:textColor="#android:color/white" />
</RelativeLayout>
<TextView
android:id="#+id/main_item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/main_item_bg"
android:layout_margin="5dp"
android:maxWidth="200dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/white" />
As #Salauyou mentioned, try with android:layout_alignLeft because it "Makes the left edge of this view match the left edge of the given anchor view ID"
and android:layout_toLeftOf means "Positions the right edge of this view to the left of the given anchor view ID."
Now, this is what I achieved:
I used this picture in drawable-mdpi (as the badge) - note the trick of the dual background:
and the standard launcher icon, since I didn't have a wine glass icon handy.
This is my layout:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:layout_margin="0dp"
android:padding="0dp"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="0dp"
android:padding="4dp"
>
<TextView
android:id="#+id/txtIcon"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentRight="true"
android:gravity="center"
android:padding="4dp"
android:background="#6b2339"
android:drawableRight="#drawable/ic_launcher"
/>
<TextView
android:id="#+id/txtBadge"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_toLeftOf="#id/txtIcon"
android:gravity="center"
android:padding="4dp"
android:background="#drawable/wines_crossing_badge"
android:text="8"
android:textColor="#312c23"
android:textSize="16sp"
/>
<TextView
android:id="#+id/txtDesc"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#id/txtBadge"
android:background="#312c23"
android:gravity="left|center_vertical"
android:padding="4dp"
android:text="Available Androids in stock for rental"
android:textColor="#fff"
android:textSize="16sp"
/>
</RelativeLayout>
</RelativeLayout>

android LinearLayout - ImageView gets pushed off the screen

I use the layout posted below to show messages by inflating that layout as a row into a ListView. The problem is that it works fine with a single-line message but when there are 2 lines or more the ImageView indicating the message state gets pushed off the screen, can't get the reason. Any ideas? Layout code and screenshot below.
That is the inflated layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp" >
<TextView
android:id="#+id/tvTimestamp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="TextView"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="8sp" />
<LinearLayout
android:id="#+id/rl_message_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_toRightOf="#+id/tvTimestamp"
android:background="#drawable/outgoing_bg"
android:orientation="horizontal" >
<TextView
android:id="#+id/tvMessageOutgoing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="#+id/imgMessageState"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="bottom"
android:src="#drawable/ic_launcher" />
</LinearLayout>
</RelativeLayout>
change you linear layout width fill_parent
and add android:layout_weight="1" in textview
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp" >
<TextView
android:id="#+id/tvTimestamp"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="20"
android:gravity="center_vertical"
android:text="10:20pm"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="8sp" />
<RelativeLayout
android:id="#+id/rl_message_holder"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="80" >
<TextView
android:id="#+id/tvMessageOutgoing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/imgMessageState"
android:padding="4dp"
android:singleLine="false"
android:text="android developer tutorial in the world"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="#+id/imgMessageState"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_gravity="bottom"
android:contentDescription="#string/app_name"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
</LinearLayout>
This worked for me
<TextView
android:id="#+id/tvMessageOutgoing"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="4dp"
android:layout_weight="1"
android:text="Medium Tesssssssssssssssssssssssssssssseeeeeeeessssxt"
android:textAppearance="?android:attr/textAppearanceMedium" />
It gives the textview the remaining space.
Try like this
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="0.6"
>
<ImageView
android:id="#+id/imgMessageState"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="bottom"
android:src="#drawable/ic_launcher" />
</LinearLayout>
Define your image view layout inside of Linear Layout
You can use
android:drawableRight="#drawable/ic_launcher"

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