Android: how to make multiline text auto scroll down? - android

I want to make the multiline text auto scroll down as I add in more text:
<EditText
android:id="#+id/Text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/TypeBox"
android:layout_below="#+id/ReceiverName"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_weight="0.65"
android:ems="10"
android:focusable="false"
android:gravity="bottom"
android:inputType="textMultiLine|textNoSuggestions" >
</EditText>
I have tried searching for it but all i could find is auto scroll of a text box within a scroll view.

android:inputType="textMultiLine"
android:editable="true"
android:enabled="true"
android:minLines="6"
android:maxLines="6"
android:isScrollContainer="true"
android:focusable="true"
Refer this link for more info
https://alvinalexander.com/source-code/android/android-edittext-isscrollcontainer-example-how-make-multiline-scrolling

I think, you need to add a line:
android:inputType="textFilter|textMultiLine|textNoSuggestions"

Add bellow code in activity onCreate(), this Add scroll behavior to
text view
textView.setMovementMbehavior ScrollingMovementMethod());
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:text="text"
android:textColor="#ffffff"
android:textSize="20sp"/>

Related

Edit text overlaps each other

I am creating an android application in which i am collecting user's some messages.But i am getting some issues such as following..
I have added 3 edit text in alert dialog..the third edit text box having multi line textbox so whenever i am adding multiple lines its getting overlapped to above two edit text
here is the snapshot of the error
Here Is Layout file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<ScrollView
android:layout_width="245dp"
android:layout_height="245dp"
android:layout_weight="0.40"
android:layout_gravity="center_horizontal">
<RelativeLayout
android:layout_width="245dp"
android:layout_height="200dp">
<EditText
android:layout_width="235dp"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/editText6"
android:layout_gravity="center_horizontal"
android:hint="Your Email Id"
android:layout_alignBaseline="#+id/editText5"
android:layout_alignBottom="#+id/editText5"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="240dp"
android:layout_height="wrap_content"
android:id="#+id/editText4"
android:layout_gravity="center_horizontal"
android:hint="Title"
android:singleLine="true"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="236dp"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:id="#+id/editText5"
android:hint="Description"
android:layout_gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" /></RelativeLayout></ScrollView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:id="#+id/button10"
android:layout_gravity="center_horizontal" />
</LinearLayout>
Reason for your issue is android:inputType="textMultiLine" pushes content when there is a new line!
You can use android:maxLines="1" for your EditText [any way this will be useful for you since you have used android:singleLine="true" with is kind of dipricated ]
Ps: Hard coding android:maxLength will not solve your issue since screens can be in different sizes which makes you hard to decide how many lines you keep!
Also you can use android:maxHeight="xdp" for the editText view, then the limit won't exeed!
You should use
android:maxLength="4"
row numbers you want to fix for your edit text
Use LinearLayout with vertical orientation instead of RelativeLayout.
If u want to use RelativeLayout, then set layout_below attribute of RelativeLayout.
You need to set android:maxLines="4". Set your max lines to solve this issue.
<EditText
android:id="#+id/editText4"
android:maxLines="4"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:hint="Title"
android:layout_alignParentStart="true" />
You can use android:layout_below and android:layout_marginTop in your EditText views and keep distance between your views.
Example :
<EditText
android:layout_width="236dp"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:id="#+id/editText5"
android:hint="Description"
android:layout_gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/editText4"
android:layout_marginTop="20dp"/>

How to make cursor stay in the center of edittext

I have a normal edittext like this :
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/et_word"
android:ems="12"
android:background="#android:color/transparent"/>
How can I make the cursor stay always in the center of edittext? No matter if user enters something or not. Thanks.
Try adding the following code
android:gravity="center"
This makes sure that your text will always be entered in the center of the EditText. By default its value is left.
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/et_word"
android:ems="12"
android:gravity="center"
android:background="#android:color/transparent"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="start"
android:maxLines="1"
android:gravity="center"
android:hint="Some hint text"
></EditText>
please Try adding the following code
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="start"
android:maxLines="1"
android:gravity="center"
android:id="#+id/et_word"
android:ems="12"
android:background="#android:color/transparent"/>
Here you can add to property in xml file to gravity center then you can get cursor center
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/et_word"
android:ems="12"
android:gravity="center"
android:background="#android:color/transparent"/>
That can be write from center also.

Text hint vertically in EditText in Android?

Check This Image:
<TextView
android:id="#+id/cusumerName"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:paddingLeft="10dp"
android:background="#drawable/button"
android:hint="Consumer Name"
android:textColor="#660000"
android:textSize="15sp" >
</TextView>
Here I found Text hint on Top, I want it vertically, How can I do?
use this in xml of TextView:
android:hint="H\ne\nl\nl\no"

Android EditText text is not vertically centered

I have search bar that defines EditBox like
<EditText
android:id="#+id/search_editbox"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_toLeftOf="#id/search_execute_imageview"
android:layout_toRightOf="#id/layout_back_logo"
android:gravity="left"
android:hint="#string/search_hint"
android:maxLength="20"
android:textCursorDrawable="#null"
android:drawableRight="#drawable/abc_ic_clear_holo_light"
android:background="#drawable/rounded_edittext_states"
android:padding="5dip"
android:singleLine="true"
android:textSize="#dimen/main_text_size" />
Despite android:layout_centerVertical="true" the text is not in the middle, but closer to upper side.
Use
android:gravity="left|center_vertical"
The correct answer is right but it is recommended to use:
android:gravity="start|center_vertical" instead of ("left") to avoid formatting errors.
try this:
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="56dp"
android:ems="10"
android:gravity="left|center_horizontal"
android:textAlignment="center" >
</EditText>
just change your gravity value to "left center align".
android:gravity:"left|center"

Android App Widget - How To Create TextView Marquee On Two Separate Lines With Adjustable Scrolling Speeds?

I'm trying to create a widget with several different lines on it and want to set it to auto scroll (marquee) and have the ability to adjust the scrolling speed. How can I accomplish this?
I tried using a TextView and was able to make it scroll on one line, but that's it. I can't seem to adjust the speed of it or have two lines scrolling at the same time.
An example of this is: https://play.google.com/store/apps/details?id=huntsman.stocktickertapelite&hl=en
OR
https://play.google.com/store/apps/details?id=com.cousinHub.widget
Anyone have an idea of how they did it? (custom views?)
Thanks.
This is what I have so far:
<TextView
android:id="#+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:textStyle="bold"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/app_name"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:duplicateParentState="true"
android:layout_weight="1">
<requestFocus
android:focusable="true"
android:focusableInTouchMode="true"
android:duplicateParentState="true" />
</TextView>
Try this, I am getting the text from Java as setText file, and show in this screen
<ScrollView
android:id="#+id/SCROLLER_ID"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/line_dotted"
android:layout_marginBottom="10dp"
android:fillViewport="true"
android:scrollbars="vertical" >
<TextView
android:id="#+id/text_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="15sp"
android:layout_marginRight="15sp"
android:layout_marginTop="10sp"
android:scrollbars="vertical"
android:textColor="#0A2A1B"
android:textSize="12sp" />
</ScrollView>
Or You can try this without scrollview, the text will scroll when there is more than 5 ines
<EditText
android:id="#+id/Comments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/Submitbtn"
android:layout_alignParentLeft="true"
android:layout_below="#+id/ratingBar"
android:layout_marginBottom="40dp"
android:ems="10"
android:gravity="left"
android:hint="Comments"
android:maxLines="5"
android:padding="20dp"
android:scrollbarStyle="outsideOverlay"
android:scrollbars="vertical"
android:imeOptions="actionDone" />

Categories

Resources