Characters appear out of the screen in the TextView! - android

Hey, I've been trying to fix this problem for a long time, The problem
is that some characters in the text are out of the screen, here is a
screenshot of what I mean:
xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#drawable/list"
android:orientation="vertical"
android:padding="15dip"
android:layout_width="fill_parent"
android:id="#+id/relativeLayout1"
android:layout_height="fill_parent">
<TextView
android:textSize="20sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000"
android:id="#+id/Munawwat_Text_TextView_text"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
Can anyone suggest a way/workaround to fix this problem?
A workaround for this is to put it into an EditText. If I put the text
into the EditText, the EditText gets horizontally scrollable
(scrollable for ~3px) which is good so you can see the characters that
are out of the screen but i dont want to let the users mess with the
text.. So:
Is it possible to not allow the users to edit in the EditText and
in the same time let the EditText get scrollable?
Is there any other view that i can put the TextView into it, so it
can get scrollable a bit so I can see the characters? (limit the
scroll of the view)
Is there a way to limit the number of characters in each line in
the TextView?
I know I asked a lot though this is one of the last problem I have so
I would really appreciate any comment/suggestion!
Thanks.

You could wrap your TextView in a ScrollView. Or make the text smaller. Or try adding padding on the left to see if it forces linebreaks.

and try to use weight :D
it limites number of caracteres in textview
android:maxLength

Related

Telegram android message cell

I am trying to make a layout like Telegram message box in android.
When the text is short the message and time are aligned in one single line as follows:
But when the message text is longer the time text view is pushed to the bottom of message like this:
How can i achieve this?
P.s. I tried to read the telegram source but wasn't able to figure it out. And i tried to get the size of my text view in adapter but wasn't successful.
Your shown example looks like a RelativeLayout with two TextViews in it (first TextView top-left and second TextView bottom-right).
It should be possible to accomplish this by using a RelativeLayout and two TextViews. The TextViews should be positioned correctly based on the length of the text (the second TextView displaying time should be always in bottom-right corner).
Actually they are not aligned in one line... :D I think you can achieve this by wrapping your TextView for time in RelativeLayout like that:
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/background"
android:padding="10dp" >
<TextView style="#style/TextView_port"
android:id="#+id/text"
android:text="Text" />
<RelativeLayout style="#style/LinearLayout"
android:layout_below="#id/text"
android:layout_margin="10dp"
android:gravity="right" >
<TextView style="#style/TextView_port"
android:text="3:59pm"
android:textColor="#73B661" />
</RelativeLayout>
</LinearLayout>
Here i found a trick to set your text alignment to justify:
https://dzone.com/articles/android-%E2%80%93-how-display
EDIT
I finally came up with the solution - the edited code above is for short texts. Check programatically the length of the text and if it is more than 20 for example set orientation of the Linear to vertical and only top margin of the time TextView to -20 - I'll update my answer later if you don't know how :)

Fixed-width TextView with stretched compound drawable

I'm trying to achieve the following layout: a fixed width TextView aligned to the left of its parent, with the text inside it aligned to the right side of that TextView (that's why fixed width, can it be done other way?) and the rest of the parent is filled with a drawable (simple line). Like this:
It's a ListView containing 2 types of rows and the layout for the rows with lines is quite trivial - LinearLayout with TextView and ImageView (I can post the exact code later if needed). And I'm getting a warning that it could be replaced with a single TextView with compound drawable.
I'm all for optimization so I really tried to follow that advice. Unfortunately I wasn't able to get the same result - the line is either constrained to TextView's width or text is aligned to the right side of the ListItem, now to fixed position.
Am I missing something?
Edit: Apparently it is not actually possible and since there are some other complications (the drawable is now a level-list drawable, which is not always a line and sometimes it has a non-fixed height that I have to set) I will leave it as it is now - linear layout, containing one TextView and one ImageView.
I don't think that you're missing anything. The TextView compound drawable features are not very customizable and in general are not worth the time you spend trying to get them to look right. Some lint warnings are a little overzealous and premature.
The optimization that the lint refers to is something that is better attributed for a fixed size image. In your case, the line has to stretch the rest of the screen length and as such it is not something that can be done with a textview with compound drawable. This kind of lint warning is more of a suggestion rather than something that MUST be done and is detected by just checking for a linear layout with only a textview and an imageview rather than checking what would need to go in the image view. If you already have it working the way you did it I think you should leave it alone.
Your view create from this -
<?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" >
<TextView
android:id="#+id/time"
android:layout_width="#dimen/today_time_width"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:gravity="right"
android:layout_marginRight="5dp" />
<ImageView
android:layout_gravity="center"
android:id="#+id/border"
android:layout_width="match_parent"
android:layout_height="#dimen/today_current"
android:src="?attr/item_boundary" />
</LinearLayout>
There is no way to achive this using only standart TextView. If you really want to reduce view count you can create your custom TextView class, set layoutWidth to matchParent and draw line from text end to right border. But it's not worth to be doing. Some extra views won't slow your list.
I am not sure if you will be able to achieve what you really want to , but then you could change the linear layout in the link you posted to something like this:
<RelativeLayout
android:id="#+id/relTrial"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/txtTime"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:gravity="right"
android:text="12:45 AM"
android:layout_alignParentLeft="true"/>
<LinearLayout
android:id="#+id/lnrSep"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:gravity="bottom"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_centerVertical="true"
android:orientation="horizontal"
android:background="#android:color/darker_gray"
android:layout_toRightOf="#+id/txtTime"
android:layout_alignParentRight="true"></LinearLayout>
</RelativeLayout>
This way the time text will be right aligned although being at the left side, and the line will also be visible.
Hope that helps.
If I got you right, you want to add bottom border to list view item?
What about to try this:
android:drawableBottom="#drawable/line"

How to make sure specific view is visible when keyboard appears?

I have a layout with a graphic at the top, an EditText in the middle and a button some distance below it, like so:
When the user is typing in the EditText, I want to pan the layout so that the "Go" button is still visible, even if that means clipping the image off the top, like so:
I know about windowSoftInputMode="adjustPan" in the manifest, but that doesn't work because it only pans far enough for the EditText to be visible. Is there a way to make sure it pans until the button is visible too?
For comments with K_Anas, this is my layout. It has all the extra margins and spacing removed compared to the first screenshot, to remove any other source of problems.
<?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="fill_parent">
<View
android:layout_width="300dp"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:background="#999"/>
<EditText
android:layout_width="280dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:hint="Sample..."/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Go"/>
</RelativeLayout>
Spoke with the Android developers hangout, and it doesn't seem like there's an easy way to solve this problem. The consensus seems to be reworking the layout rather than having an API to fix the issue.
did you tried:
android:windowSoftInputMode="adjustResize"
in your activity Tag in Manifest
see these docs on android developer blog
I tried your layout with: android:windowSoftInputMode="stateVisible|adjustResize"
and give me these results:
I'm sure it isn't the BEST way, but couldn't you just change the layout attributes for your button (add/change a margin) and redraw when the edittext is clicked? Use an onClickListener & maybe invalidate your button.

How to display multiple lines of text with scrolling in android?

I want to display multiple lines of text in my application in particular range such that user can scroll to view other lines. I have tried EditText, but it generates keyboard on top of it and doesn't scroll properly. Then I tried TextView, it also does not scroll the text properly as I wanted.
Is there any other option available? If No, then how to scroll the text vertically in TextView or EditText? I want to scroll the text on drag as in WebView. NOT auto scroll.
You can limit the Height of TextView to match the number of lines you user wants to see, then simply put your TextView in a ScrollView
I had done a simple example to demonstrate this...
<ScrollView android:layout_height="30dp"
android:layout_width="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="30dp"
android:textSize="16sp"
android:id="#+id/tv1"
/>
</ScrollView>
Check below code
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#000000"
android:textSize="17dip"
android:inputType="textMultiLine"
android:scrollbars="vertical"
/>
It is possible to create multiline text view with scroll view. I used the following code in your application:
Txt_VistaRecetasola = (TextView) findViewById(R.id.txt_vistarectsola);
Txt_VistaRecetasola.setMovementMethod(ScrollingMovementMethod.getInstance());
Txt_VistaRecetasola.setScrollBarStyle(0x03000000);
Txt_VistaRecetasola.setVerticalScrollBarEnabled(true);
Txt_VistaRecetasola.setTextColor(0xFF000000);
Try using Edittext with making it un editable, so in this case it wont allow keyboard to popup.
android:windowSoftInputMode="stateAlwaysHidden" in your Manifest file in the activity where you have your EditText.

Text align to right and bottom of another text

Excuse my next picture, done in a hurry :):
Please can anybody tell me how can I use Layouts and TextViews in Android to get something similar with I draw.
The box with one TEXT is a String and also the box with TEXT TEXT TEXT is a String.
Thank you.
I don't thing you can use 2 TextView instances for this situation. A workaround could be to use only one TextView and do your text formatting programmatically.
In the RelativeLayout, inside each TextView tag use these attributes as per your requirement
android:layout_below="Id of the TextView"
android:layout_above="Id of the TextView"
android:layout_toLeftOf="Id of the TextView"
android:layout_toRightOf="Id of the TextView"
something like this should do the trick. The keys are layout_below and layout_toRightOf
<RelativeLayout
android:layout_width="fill_parent" android:layout_height="fill_parent">
<TextView android:id="#+id/LeftTextView"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:paddingRight="10dp" android:paddingBottom="10dp"
android:text="HI">
<TextView android:id="#+id/WholeTextView"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:layout_below="#id/LeftTextView"
android:layout_toRightOf="#id/LeftTextView">
</RelativeLayout>
For some reason, that's a bad approach even if it works. I would suggest use a different textview for the bottom row. It may work with some combination in Relative Layout, but it may probably not be the same in each and every screen/resolution.
Have you tried using compound drawables?
textview2.setCompoundDrawables(textview1, null, null, null);

Categories

Resources