Text view losing characters that is to be displayed [Android] - android

I have a text to be displayed in a text view. The text contains 200 lines of data, each line is having 10 characters. So total 2000 characters. The text view is inside a vertical scrollable view. The first 50 lines are not getting displayed. If the text view had a limitation to the number of characters, then its fair enough if it loses the last few lines, but why is it taking off the head??.
And also what is the limit on the number of characters for a text view??
My code:
<ScrollView
android:id="#+id/scroll_layout_ECG"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/btn_ECG"
android:layout_alignLeft="#+id/btn_ECG"
android:layout_alignStart="#+id/btn_ECG"
android:layout_marginBottom="16dp"
android:layout_marginTop="16dp" >
<TextView
android:id="#+id/tvECG_samples"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:hint="ECG\nsamples"
android:textSize="25sp" />
</ScrollView>
In the 1st screen shot, the data is being shown from 51st line. The first 50 lines are clipped off. Why??

no need of external scrollbar rather than u can use textview's property
android:scrollbars="vertical"
I think It will help u

Related

How to limit lines on a TextView

I'm trying to limit a TextView to 1 line, the length of the screen. I'm having trouble keeping it from expanding.
I've tried adding the
android:minLines="1"
android:maxLines="1"
attributes to the TextView xml. This does keep the view from expanding, but this does not limit the characters of the text. For example, if I have entered the maximum number of characters in a line and proceed to add a '(' to the string, I can see the top of it printed below the first line.
Basically, I need a way to limit the amount of characters to the width of the screen. I've tried this:
while(txt.getLineCount() > 1) {
txt.setText(txt.getText().subSequence(0,txt.getText().length()-1));
}
which doesn't work at all. I've also tried that same method with comparing the txt.getHeight() to the txt.getTextSize().
I'm out of ideas. What can I do?
If I use a textview this way it will ocupy only 1 line:
<TextView
android:id="#+id/textView"
android:maxLines="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
Try this. This will limit textview to single line. , if the text was more than one line it will display ... at end.
<TextView
android:id="#+id/textView"
android:singleline="true"
android:ellipsize="end"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

Vertically aligning suffix with tab space in android TextView

I have rows (of horizontal LinearLayout) with a TextView at the end that displays time. An this is how it looks:
Now I need the suffix (am/pm) in all rows to be aligned vertically. This is not the case in the above layout, as you can see, the last row is misaligned as the displayed time is longer.
I achieved this using the tab character \u0009. This means I would set the text to be for example "7:21\u0009\u0009pm". This produces desired result as show below:
However, I need to know if (1) this is the most efficient way and (2) that this would work on all android devices. If there is an alternative way to achieve this please let me know.
And here is an XML layout of a row for your reference:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="#dimen/prayer_time_row_height"
android:layout_marginLeft="48dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<com.devspark.robototextview.widget.RobotoTextView
style="#style/text_subhead"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Today"
android:textColor="#color/material_light_secondary_text"
android:visibility="invisible" />
<com.devspark.robototextview.widget.RobotoTextView
style="#style/text_subhead"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Event"
android:textColor="#color/material_light_primary_text" />
<com.devspark.robototextview.widget.RobotoTextView
style="#style/text_subhead"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="12:06\u0009\u0009am"
android:textColor="#color/material_light_primary_text" />
</LinearLayout>
BONUS
Bonus points for pointing out a way to vertically align the hour-minute separator, i.e., colon character.
Maybe using tabs is the most efficient, but the gap is pretty big and not configurable. If you need all those rows in a single view group, you may try to check out RelativeLayout: align am/pm vertically on common left, and put hours to the left and on the baseline. This is the most flexible way, since you can control relative positions and margins, but computation-wise it's less efficient because it requires extra calculation upon laying out elements.
As per aligning colons — in most fonts (not just monospace) digits are designed to take equal space, so just align the numbers on the right (e.g. in relative layout) and it should do.
For the colon character, you could try using the character "\uee01" instead of ":". This is what google does with the clock in the lock screen.
https://github.com/android/platform_frameworks_base/blob/master/packages/Keyguard/src/com/android/keyguard/KeyguardStatusView.java#L247
You can use a 2-column TableLayout. The first column is the time without AM/PM and the second column is just the AM/PM. Set the gravity of the first column to "end" or "right" and the times will be lined up at the colons if you are using a fixed width font.

Display view to right of text

I want to display text (track title) and a view to right of the text. Like on the image below.
The view (image on the screenshot above) should always be visible. The view should be displayed right after the text if there is more room than necessary. The text should be truncated if there is not enough room.
The issue is: if the text is long enough the view is not displayed or displayed in smaller size.
Please don't recommend me to use text view with a drawableEnd attribute because the view not always will be an image view.
Here is the layout I use:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:id="#+id/trackTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="1"
android:ellipsize="end"
android:text="#string/placeholderTrackTitle"
android:textSize="#dimen/track_name_height"
android:textColor="#color/queue_text_color"
android:layout_weight="0"/>
<ImageView
android:id="#+id/downloadedIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_downloaded"
android:layout_gravity="center_vertical"
android:layout_marginLeft="#dimen/queue_horizontal_margin"
android:layout_marginRight="#dimen/queue_horizontal_margin"
android:layout_weight="1"
android:contentDescription="#string/downloaded_icon_description"/>
</LinearLayout>
Use the maxWidth attribute on the TextView and ellipsize the text in case of overflow.
edit: or MaxLength, MaxLines, or MaxEms, whichever works better for your purposes
ok, there are few solutions that i have used and it works good.
Check the below one:
1) Android: Something better than android:ellipsize=“end” to add “…” to truncated long Strings?
2) How to truncate TextView, and then add ellipsis in Android

How to truncate TextView, and then add ellipsis in Android

I have read a few of the other threads here with similar concerns, but none of their answers seemed to work for me.
Can't get ellipsis to work on Android
Android: Something better than android:ellipsize="end" to add "..." to truncated long Strings?
I have a Relative Layout with 2 elements, a text view and an image view. I need the text view to be 1 line and to truncate about 5sp short of the image view and apply ellipsis to the end of the text.
<RelativeLayout
android:id="#+id/title_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5sp">
<TextView
android:id="#+id/"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textSize="10sp"
android:textColor="#FFFFFF"
android:text="title"
android:maxLines="1"
android:ellipsize="end"/>
<ImageView
android:id="#+id/"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="5sp"
android:layout_marginLeft="5sp"
android:background="#drawable/home"/>
</RelativeLayout>
In the above code, I was attempting to apply a margin left to the Image View to force the text view to its left to truncate by as many sp as I put in the margin.
The code above would truncate the text view to a single line and add (...) but only to the end of that line; irrespective of the ImageView to it's right, regardless of whatever margin I apply to it. The Image View appears above the text. I figured this may be due to them being in a relative layout.
Any help in figuring out how to make the text view respect the margin/space taken up by the image view would be greatly appreciated.
I believe what you want to do is to first place the image view (with margins) and then set the text to align to the left border and to be placed to the leftOf the image.

Is there any character limit in android textview?

I'm trying to enter more than 2000 - 3000 characters in an android TextView
it does not display anything.
any one guide is there character limit on android textview or what ?
I did some small testing in G3, I found that:
If there is a TextView in the activtiy layout, it can show more than 4096
characters, but when it owned by the item of listview, it just display
invisible. So there's no hard limit, just what can be displayed depending on the device.
Post your code might be your textview expand and fill the screen use Scrollview to handle this issue.
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:alpha="0.75"
android:gravity="center_horizontal"
android:textAppearance="#android:style/TextAppearance"
android:textColor="#color/alert_dialog_heading_text_color"
android:textSize="#dimen/text_size_for_subheading" />
</ScrollView>

Categories

Resources