Android TextView text cut off only in Gingerbread - android

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"

Related

Android Marshmallow breaks old layout

My app was first developed for Android 2.3, but has been updated many times and currently targets V21. So I was surprised when my Nexus 5 received the Marshmallow update and found that a critical feature of my app was broken. I have a screen with a line at the top where I want two buttons at the far right and an EditText box (for search text) filling up the remainder of the screen to the left. This was my first app and I was unclear about various layout techniques, but from Android 2.3 to 5.1 this code has continued to work:
<RelativeLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/upper_detail_section"
android:elevation="#dimen/upper_elevation"
>
<Button android:id="#+id/sort"
style="#style/large_cust_btn"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="#string/sort"
/>
<Button android:id="#+id/clear"
style="#style/large_cust_btn"
android:layout_toLeftOf="#+id/sort"
android:layout_alignParentTop="true"
android:layout_alignWithParentIfMissing="true"
android:text="#string/clear"
/>
<EditText android:id="#+id/lookup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/clear"
android:layout_alignBaseline="#+id/clear"
android:singleLine="true"
android:hint="#string/item_search_hint"
android:scrollHorizontally="true"
android:textSize="16sp"
android:inputType="textFilter"
/>
</RelativeLayout>
Bringing this screen up in Android 6.0, the buttons are there but the EditText field completely disappears! Knowing what I know now it turned out to be a simple fix using a LinearLayout and weighting:
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/upper_detail_section"
android:orientation="horizontal"
android:elevation="#dimen/upper_elevation"
>
<EditText android:id="#+id/lookup"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:singleLine="true"
android:hint="#string/item_search_hint"
android:scrollHorizontally="true"
android:textSize="16sp"
android:inputType="textFilter"
/>
<Button android:id="#+id/clear"
style="#style/large_cust_btn"
android:text="#string/clear"
android:onClick="clearClicked"
/>
<Button android:id="#+id/sort"
style="#style/large_cust_btn"
android:text="#string/sort"
android:onClick="sortClicked"
/>
</LinearLayout>
So all is well now and I'm updating the store with a new APK, but I thought I'd warn people that some layout tricks that used to work may now be broken.
If I'm understanding and reproducing your problem correctly, it's quite simple to fix your issues with RelativeLayout as well. Marshmallow only handles a width of match_parent differently. So just set it to something else like with the LinearLayout and alignParentLeft to true:
<EditText android:id="#+id/lookup"
android:layout_alignParentLeft="true"
android:layout_width="0dp"
[...] />
This yielded the same layout for me like in pre Marshmallow.

Ellipsize not working (for single line)

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

TextView text not wrapping on Android 4.3

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.

why sorry pop up cause of text size?

I have a layout with a textview and a button as below.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
style="#style/info_layout">
<TextView
android:id="#+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp" />
<Button android:id="#+id/butn1"
android:layout_gravity="center_horizontal"
android:layout_marginTop="40dip"
android:layout_width="150dip"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/button1" />
</LinearLayout>
The above layout works fine for many languages but for arab its giving sorry pop up, but if i change textSize to 18sp it works fine. Even i tried removing margin from button before changing text size but still the problem raises.I'll set text for text View in java file.So im not understanding what's exact cause for this problem.
01-08 03:09:59.959: E/AndroidRuntime(1803): java.lang.StringIndexOutOfBoundsException: length=75; regionStart=52; regionLength=-18

Text in TextView not shown in multiple lines - it gets truncated in a single line

Below is an outline of my layout. I have my ScrollView inside another LinearLayout because I would be adding more views to it in runtime.
Anyway, the problem is - the text in the TextView is always truncated to a single line, and is never shown in multiple lines.
Is there any way to make it display a multilined TextViw without having to set an arbitrary number of lines using android:lines or android:maxLines?
Thanks.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:background="#drawable/background"
android:id="#+id/XyzLayout"
android:paddingRight="10dp">
<ScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#drawable/background"
android:fillViewport="true">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="vertical"
android:layout_marginBottom="0dip" android:layout_marginTop="1dip">
<TextView android:id="#+id/textView1"
android:text="#string/String1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginTop="20dip"
android:layout_marginRight="10dip" android:textSize="18dip"
android:typeface="sans" android:textStyle="bold"
android:layout_marginBottom="4dip"
android:inputType="text|textMultiLine"/>
<TextView android:id="#+id/textView2"
android:text="#string/String2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginTop="20dip"
android:layout_marginRight="10dip" android:textSize="16sp"
android:typeface="sans" android:textStyle="bold"
android:layout_marginBottom="4dip"
android:inputType="text|textMultiLine"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
i've got this problem with a i5800 with CM7(2.3.7) and the emulator and works fine on a SGS-i9000 with CM9 (4.0.3).
The problem was setting the theme at the manifest:
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#android:style/Theme.DeviceDefault" >
I put " android:theme="#android:style/Theme.Holo " and if the device doesn't have it, the textview doesn't allow MultiLine.
You can use the library " holoeverywhere " to port the holo theme to all devices.
Regards.
Try deleting the setting android:inputType="text".
Just had the same problem. I had android:multiLines="2", then I tried android:lines="2", then tried adding android:singleLine="false", but still my EditText would only show one line. I could scroll horizontally to get to the end of my line. What ended up working was deleting the setting android:inputType="text" . This allowed me to type in a long line that would wrap around to a second line.
It could be false by default but did you try to add this in your TextView
android:singleLine="false"
-serkan
To add to #KNU's answer...
Here's a good related answer showing that you can use a different theme depending on the version of Android it is running on - just create a versioned styles folder.
Answer here: TextView won't break text
Set input type as inputType="text|textMultiLine". This made to resolve my issue.
<TextView
android:id="#+id/itemTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text|textMultiLine"
android:textSize="#dimen/text_size_12"
android:layout_gravity="center"
android:gravity="center"
android:text="Your Text Here"/>

Categories

Resources