How to display multiple lines of text with scrolling in android? - 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.

Related

How to fix imageview positions but have variable textview above them in Android

I am currently working on an app and my layout is as follows:
I have a recyclerview holding all of my items, each item has a textview above an imageview. So the text view can expand up to 3 lines but only if needed. The recyclerview is using a gridlayout manager to display all of my items.
The problem is that currently when the text view expands to have more than 1 line it presses down the image instead of keeping it aligned with the other images in the row
What I currently have
What I want is to prevent the text view from pressing down on the image but instead build it's way up so that way the images stay normal and the text view will grow upwards like the image below.
What I want
Is there any way to achieve this? I would think it shouldn't be hard but I can't seem to find a way to accomplish this, or more likely, can't google the right terms to find the solution I'm looking for.
So I found an answer, I had to set two properties for my textview:
android:lines="3"
android:gravity="bottom"
so in the end each item had a layout below:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingStart="31dp"
android:paddingEnd="32dp">
<TextView
android:id="#+id/app_name"
android:layout_width="#dimen/product_list_image_dimensions"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="#string/app_card_temp_name"
android:textSize="#dimen/product_list_text_size"
android:fontFamily="sans-serif-condensed"
android:lines="3"
android:textAlignment="center"
android:textColor="#color/app_name_product_list_color"
android:typeface="normal"
android:gravity="bottom" />
<ImageView
android:id="#+id/app_thumbnail"
android:layout_width="#dimen/product_list_image_dimensions"
android:layout_height="#dimen/product_list_image_dimensions"
android:layout_below="#id/app_name"
android:paddingTop="#dimen/product_list_text_bottom_padding"
android:scaleType="centerCrop"
android:layout_centerHorizontal="true" />
</RelativeLayout>

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 :)

Android multiline EditText

I've one EditText with multi-lines.
The problem is that, while I am adding more and more lines, just pressing ENTER or typing, the EditText keeps scrolling down which is OK, but after approx. 10 lines whole activity is scrolling.
And when I click again on EditText, the opened keyboard covers whole EditText.
But, when I click only on 3rd line, keyboard isn't covering EditText and View is moved like it should have.
Any advice please?
Okay,Using EditText in ScrollView Like this way
<ScrollView
android:layout_height="100dp"
android:layout_width="match_parent">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#54D66A"
android:textSize="17sp" />
</ScrollView>
For programmatic approach please check
http://developer.android.com/reference/android/text/method/ScrollingMovementMethod.html
You can give android:maxHeight="60dp" to your EditText to stop scrolling of the whole Activity and it will solve other problem also.
I hope it helps.

Scroll horizontal in disabled edittext

An edittext turn enabled or disabled in code (if "EDIT" button is pressed or not).
The problem is: if edittext contains a large text and his status is disabled, i can't scroll horizontal for view all text. (if his status is enabled, i can scroll horizontally normally)
if you wrap your EditText in HorizontalScrollView the user can scroll it horizontally even if EditText is disabled :
<HorizontalScrollview
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</HorizontalScrollView>
You can use the following parameters in the edittext.
edittext.setFocusable(false);
edittext.setClickable(false);
edittext.setFocusableInTouchMode(false);
edittext.setEnabled(true);
edittext.setKeyListener(null);
edittext.setHorizontallyScrolling(true);
So it will work as the desired behaviour.
This is my Edittext in XML
<EditText
android:id="#+id/et_myEdtitText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:maxLines="1"
/>
and in JAVA add this,
et_myEdtitText.setKeyListener(null);
Now i won't be able to add any text in Edittext. Because, i have disabled KeyListener, But i will be able to scroll your Edittext horizontally

Characters appear out of the screen in the TextView!

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

Categories

Resources