I am developing a simple math calculator for Android. I want to know how I can make the textview scroll horizontally to the left when the input is long and has exceeded the textview width. I have tried using
android:ellipsize="Marquee"
But this will make the textview not showing inputs. I also tried:
android:scrollbars="horizontal" and
android:scrollhorizontally="true".
But none worked for me.
Wrap your TextView inside Horizontalscrollview
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:fillViewport="true"
android:measureAllChildren="false"
android:scrollbars="none" >
<TextView
.../>
</HorizontalScrollView>
Related
Going crazy with this one here,(just to be clear: I looked at all the questions here on stackoverflow regarding "scrollview not working" and none of them helped). The following is a short version of what I'm trying to do
<ScrollView
android:id="#+id/week_View"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Monday" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Monday" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Monday" />.....
.............
</LinearLayout>
</ScrollView>
Textview is repeated multiple more times inside the linearLayout if that is not cleared and I want it to scroll horizontally. What I'm getting is:
You see the textView at the end getting "squeezed" and the rest of the textviews are not even displayed and scrollview doesn't go left or right. What am I doing incorrectly? (The scrollview is wrapped in a RelativeLayout).
ScrollViews are always vertical, meaning they go up and down. Use a HorizontalScrollView instead.
As you have got n number of textViews its better to use
a recyclerview with horizontal layout manager as it wont create memories of all textviews at one go
or,
you can use a horizontalScrollView to scroll them horizontally..
ScrollView scrolls vertically
In my scrollview, I have a textview with multilines, since in the code the text was set with maximum characters of 200, so I would like to always show all the text inside the textview as at most there are only 6 lines of text.
But the problem is when I touch the multiline textview, it disables the scrolling of it's parent. I would like to touch the textview and scroll it then the screen could go up and down, but right now it just stop in the textview and only if I touch the very right edge to find the scrollbar. I have tried to find the answers here, and mostly the pages are about how to add scrollview inside a textview that is not my case.
Any suggestions?
Here is the xml:
<com.example.VerticalScrollview xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#F7F7F7"
tools:context="com.example.EventDetailActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/eventDescription"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:textColor="#android:color/secondary_text_dark_nodisable"
android:layout_marginTop="20dp"
android:typeface="monospace"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:layout_marginBottom="20dp"
android:textStyle="italic"/>
</LinearLayout>
</LinearLayout>
</com.example.VerticalScrollview>
I haven't posted all of the xml, but above would be the one matters, remains are just other LinearLayout, Buttons, TextView, ImageView etc.
Problem solved by changing
android:inputType="textMultiLine"
to:
android:maxLines="8"
It looks like android:inputType disable the scrolling although still no idea why that happened. As my text characters won't be more than 200, then just change it to android:maxLines and problem solved. Tricky problem easy answer.
I have a horizontal scroll view that takes up the right half of the screen. On it, I have an EditText. When I select the EditText to edit the text, the HorizontalScrollView scrolls to the right. I'm guessing it's trying to place the EditText to the leftmost position. Regardless, since the HorizontalScrollView takes up the rightside of the screen, by doing this, I can no longer see the EditText since its now covered up by the contents I put on the left side of the screen. How can I prevent HorizontalScrollView from automatically scrolling when I focus on something inside its layout?
Thanks. Much appreciated.
halp
Edit: Posting code. I'm actually creating my EditText's based off of generated info, so this is not what it actually looks like, but it should capture the ideai.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<View
android:layout_leftOf="#+id/Anchor"/>
<View
android:id="#+id/Anchor"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_centerHorizontal="true"
android:background="#000" />
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_rightOf="#+id/Anchor"
android:fillViewport="true" >
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp" >
<TableRow>
<EditText>
ABOVE is the view that is going to the left
MOre views which would cause Scrolling to the right
</TableRow>
</TableLayout>
</HorizontalScrollView>
</ScrollView>
</RelativeLayout>
try this in XML the EditText if use
android:gravity="center"
remove it
I have a TextView, defined like this:
<TextView
android:id="#+id/play_info"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#color/play_info_background"
android:ellipsize="none"
android:maxLines="8"
android:orientation="vertical"
android:scrollbars="none"
android:singleLine="false"
android:textColor="#color/play_info_text_color"
android:textSize="#dimen/play_info_font_size"
android:overScrollMode="never" >
</TextView>
I set the TextView to be scrollable in code, like this:
cardInfo = (TextView) play.findViewById(R.id.play_info);
cardInfo.setMovementMethod(new ScrollingMovementMethod());
The TextView scrolls, but not smoothly, like anything inside a ScrollView.
I would like for it to scroll smoothly.
I have already tried putting the TextView (with scrolling disabled) inside a ScrollView, but this messes with the height of the TableRow it's contained in, and there doesn't seem to be a way to correct that.
The problem is if you want "smooth scroll" you have to place the TextView in a ScrollView. And when you do that, you can no longer
set the height of the TextView to "match_parent". Like, for example, when you need a large TextBox that is filled dynamically with text,
but not resized. And when you try by setting the ScrollView's attribute to "match_parent", the child TextView still wraps around the content.
I was able to do it like this:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:drawable/edit_text">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#null"
android:gravity="bottom"
android:singleLine="false"
android:typeface="serif"/>
</ScrollView>
</RelativeLayout>
A RelativeLayout container that serves as a new TextView, with the desired background, the original TextView with background set to null. So when the TextView
expands, with new text appended, it's just like text volume increasing. The text is aligned with the layout attributes if the ScrollView.
You may also need to disable scrolling for the TextView, to avoid collision with the ScrollView's scrolling in certain scenarios.
You probably missing focus attribute, Textview is not in focus so its not scrolling.
<TextView
android:id="#+id/title_itemcount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:focusable="true"
android:focusableInTouchMode="true"
android:maxLines="3"
android:padding="4dp"
android:scrollbars="vertical"
android:textColor="#android:color/background_dark" />
Hope it helps... :)
I am attempting to make a ListView inside a table consume all of the available vertical space minus the space needed for an EditText control.
I have set every attribute I can think of here to make it work:
<?xml version="1.0" encoding="utf-8"?>
<TableRow android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF0000">
<ScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="#+id/conversation"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"/>
</ScrollView>
</TableRow>
<TableRow android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#00FF00">
<EditText android:id="#+id/messagetext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text|textAutoCorrect|textMultiLine|textImeMultiLine"
android:imeOptions="actionDone"/>
</TableRow>
I must be missing something, as the result is a fully filled horizontal, but both the ListView and EditText appear to be behaving as if their attributes were wrap_content.
Is there a particular reason you're using a TableLayout? I'm not very familiar with using them yet, but what you're trying to accomplish is simple with a RelativeLayout. Also, you don't need to place the ListView within a ScrollView, the ListView handles scrolling on its own. Here is an example of how you could accomplish this using a RelativeLayout:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText
android:id="#+id/message_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#00FF00"
android:inputType="text|textAutoCorrect|textMultiLine|textImeMultiLine"
android:imeOptions="actionDone"
android:alignParentBottom="true"
/>
<ListView
android:id="#+id/conversation"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF0000"
android:layout_above="#id/message_text"
/>
</RelativeLayout>
This way, you first define the EditText to take up a certain amount of space (wrap_content, in this instance). Then, you define the ListView to fill the remaining space with fill_parent. Adding android:layout_above="#id/message_text" aligns the bottom edge of the ListView with the top edge of the EditText view.
I appear to have been missing an attribute android:layout_weight on the top TableRow. Evidently, anything over 2 makes it consume the rest of the vertical real estate. Can anybody explain why the special treatment for TableRows?
Don't use ListView inside of ScrollView, because ListView manages it's own vertical scrolling. Doing so will kill all optimization's done by the ListView
And don't anwser to your own posts. Rather edit your initial questions or add an comment.