I have a RelativeLayout containing a Textview. I want the TextView text to wrap on multiple lines.
It works fine on Android 4.1 and 4.2 (haven't tried earlier versions). However, on Android 4.3 the text doesnt wrap and is cut (see screenshots below).
Layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/feed_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/touchable_background_msf"
android:padding="#dimen/feed_item_padding" >
<com.binarymango.msfnews.images.RecyclingImageView
android:id="#+id/feed_item_icon"
android:layout_width="#dimen/feed_thumb_width"
android:layout_height="#dimen/feed_thumb_height"
android:contentDescription="Description" />
<TextView
android:id="#+id/feed_item_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/feed_item_icon"
android:layout_alignLeft="#+id/feed_item_icon"
android:layout_alignRight="#+id/feed_item_icon"
android:background="#color/text_background_msf"
android:ellipsize="end"
android:maxLines="3"
android:minLines="2"
android:padding="#dimen/feed_item_text_padding"
android:text="Description"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/text_msf" />
</RelativeLayout>
Result on Android 4.2, the text is correctly wrapped in 3 lines:
But on Android 4.3, the text is just cut:
I've been trying to play with several attributes as mentioned elsewhere in StackOverflow in vain:
android:singleLine="false"
android:scrollHorizontally="false"
android:inputType="textMultiLine"
android:width="0dip"
Also, I suspect it may have to do with the theme. My app uses Theme.AppCompat.Light
You can use android:line="3" for example to have same behaviour as the first Image.
Related
I'm trying to get ellipsize to work for a single line of text inside a TextView. I've already tried all the workarounds (e.g. scrollHorizontally, singleLine, lines, etc.) below previous questions, but nothing seems to happen. This is my code (tested on an HTC One M8 (5.0.1)):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#drawable/file_tile_background" >
<ImageView
android:id="#+id/file_tile_imageview"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="24dp"
android:src="#drawable/ic_insert_drive_file_black"
android:contentDescription="#string/file_tile_imageview_description" />
<TextView
android:id="#+id/file_tile_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/file_tile_imageview"
android:text="#string/file_tile_textview_fileName"
android:maxLines="1"
android:ellipsize="start"
android:textSize="16sp" />
</RelativeLayout>
EDIT: Maybe it doesn't like that I include this layout in activity_main.xml and doesn't use it directly?
Simple solution is to use android:singleLine="true".
You can find the related solution on the following link.
TextView's ellipsize not working on maxLines = 1
The layouts in my application are built using SDK 16 and I've tested and confirmed they work fine on ICS and JB but GB has the following issue:
In the code below, I'm just trying to create a simple layout with only text. The text keeps getting cut off on Gingerbread at the end of the first line though, instead of going on to the next line. I've tried setting singeLine to false, played around with lines, maxLines, marquee, layoutWeight, changing layoutHeight and layoutWidth to every imaginable combination, etc. This issue truly baffles me.
Code:-
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text keeps overflowing"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#33B5E5"
android:paddingTop="6dp"
/>
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text gets cut off when I input a long string like this one"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF"
/>
</LinearLayout>
</ScrollView>
Also, if I change the theme of the layout to Gingerbread, I get the error:
Failed to find style 'scrollViewStyle' in current theme
Failed to find style 'textViewStyle' in current theme
android.content.res.Resources$NotFoundException
Thanks in advance.
Fixed it myself. Couldn't find out why it was happening but I fixed it by adding the following lines to the code for TextViews:-
android:ellipsize="none"
android:maxLines="10"
android:scrollHorizontally="false"
While developing an Android application I have stumbled upon a baffling problem. The UI element I am creating is a header bar that has a custom search field. Everything looks wonderful on the Android UI editor but the second I use the emulator or a device it bugs out and compresses the magnifying glass image and clips the edit text. I have tried a number of things including changing the background image of the search area to the custom search field that is currently in the parent LinearLayout. This however results in the search field size growing out of control.
Any suggestions are welcome.
My questions are:
1) How would one fix this problem while maintaining the look of the search area?
2) Why is this problem occurring?
Confirmed on the following devices:
Samsung Galaxy Nexus 4.0.2
Motorola Zoom 4.0.3
Nexus S 2.3.7
This is a screenshot of the UI editor:
This is a screenshot of what it looks like on all devices tested:
The XML used to generate these UI elements:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/title_bar_matte"
android:gravity="center_vertical"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_margin="10dp"
android:layout_weight="1.0"
android:background="#drawable/search_field"
android:gravity="center_vertical"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="15dp"
android:src="#drawable/magnifying_glass" />
<EditText
android:id="#+id/campus_map_acitivity_search"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp"
android:layout_weight="1.0"
android:background="#0FFF"
android:hint="Search"
android:imeOptions="actionSearch"
android:singleLine="true" />
</LinearLayout>
<Button
android:id="#+id/campus_map_activity_goto_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="#drawable/button_list" />
<Button
android:id="#+id/campus_map_activity_my_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#drawable/button_location" />
</LinearLayout>
Just figured out the problem. The search background image had the top and left sides set to 9-patch scale. This is all good and well but we had forgotten to set the bottom and right fill areas so that the content would have room to exist.
http://radleymarx.com/blog/simple-guide-to-9-patch/
Remember to set the fill areas!
It turns out the Android UI editor does not handle 9-patch images like the devices. That seems to be a bug to me.
I've got a ListView with items composed of RelativeLayouts. This is the relevant XML from the list items:
<?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">
<TextView
android:id="#+id/xx"
android:gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_centerInParent="true"
android:layout_alignParentLeft="true"/>
<TextView
android:id="#+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/xx" />
<TextView
android:id="#+id/tag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/xx"
android:layout_below="#id/title" />
<TextView
android:id="#+id/subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/tag"
android:layout_below="#id/title" />
</RelativeLayout>
On Android 2.1 (tested on a Nexus One), this shows the desired behavior: Android 1.5 http://img42.imageshack.us/img42/7668/85324076.png
On Android 1.5 however (tested on a HTC Hero), it shows up like this: Android 1.5 http://img257.imageshack.us/img257/2849/72229324.png
[edit] On 1.6 (emulator), it works as expected as well.
The small grey line on the top left is what shows up in the first pic as "xx", so that should be vertically centered. As far as I can see, the XML dictates this, but for some reason, 1.5 ignores it.
Why is this? I can't find anything about this difference, and I've been brute forcing any combination of layout_center, center, alignParent*, but to no avail...
Can anyone shed some light on this? Thanks!
For relative layout layout_gravity is not used.
Also, you're using conflicting attribtues centerInParent and alignParentLeft.
Use only one of them.
You can use layout_centerVertical="true" layout_alignParentLeft="true"
RelativeLayout receives many bug fixes in 1.6 and then 2.0 :)
For one, judging by the fact that it's broken in the earliest version you're testing with and works as expected in the later versions...sounds like a bug that was fixed.
However, unless I'm oversimplifying because you're only showing a few basic sample screen shots, I would do this with nested LinearLayouts anyway.
I've noticed that layout_alignBaseline of TextVew control doesn't work with Spinner control.
I'm trying to place a text to the left of spinner, but it goes to the top of the parent control.
<Spinner
android:id="#+id/locations"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/userCode"
android:layout_alignLeft="#id/userCode"
android:layout_marginTop="15dip"
/>
<TextView
android:id="#+id/locationsLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Region"
android:layout_alignBaseline="#id/locations"
/>
Is it a bug or I do something wrong? The same technique works fine with EditText controls.
I am also facing the same problem but found the following workaround
<Spinner
android:id="#+id/locations"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/userCode"
android:layout_alignLeft="#id/userCode"
android:layout_marginTop="15dip"/>
<TextView
android:id="#+id/locationsLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Region"
android:layout_alignTop="#+id/locations"
android:layout_alignBottom="#+id/locations"
android:gravity="center_vertical"/>
Newer versions of Android support base line alignment for Spinners. The Spinner will create the first View of the list and use its baseline alignment.
If that doesn't work, make sure your spinner adapter creates a View that supports base line alignment. (getBaseline() != -1). For LinearLayouts, you can use the baselineAlignedChildIndex attribute to specify a child within the linear layout to use.
android:layout_toLeftOf="#id/locations" ?