I'm making my text scrolling as the post here.
I think I saw it was scrolling first time in another layout even without any java code.
But now, it's not scrolling anymore. No idea what's wrong with this.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?attr/actionBarSize">
<LinearLayout
android:id="#+id/scrollingTextLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#0792B5"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/scrollingText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:maxLines="1"
android:padding="5dp"
android:scrollHorizontally="true"
android:text="The culture of India is the way of living of people of India."
android:textColor="#FFFFFF"
android:textSize="16sp" />
</LinearLayout>
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/scrollingTextLayout"
android:background="#android:color/darker_gray" />
</RelativeLayout>
just put these lines in your xml:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:scrollHorizontally="true"
And in your code:
textView.setSelected(true);
It's now scrolling. I just changed maxLines="1" to singleLine="true" , you know it's a little weird. I changed singleLine to maxLines because the IDE suggested me to use maxLines instead of singleLine since it's deprecated already.
Add this code in Activity
TexView tv=findViewbyId(R.id.scrollingText);
tv.setSelected(true);
Related
I have been looking for a post to create vertical scrolling multiple textviews. similar to one shown here http://vertical-scroller.vbarsan.com/
But all post are related to creating horizontal scrolling (Marquee) textview.
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:marqueeRepeatLimit="marquee_forever"/>
I hope this helps
Have main layout as ScrollView ,Create vertical LinearLayout as child of ScrollView and create (number of textview you required ) textViews inside LinearLayout.
you should change android:layout_height
as per your code
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#FF4081"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="1st Line !" />
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="2nd line !"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="3rd line !" />
</LinearLayout>
</ScrollView>
You have 2 choice for that:
1) Use Native way: using thread, put 10 spaces before any text and in each second remove left side space and increase right space and so on, until it's limits. Hope you understood. Predefined TextView's below properties also uses this method.
2) Use predefined control TextView with below properties:
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
use this example code below it will do a marquee like html
<TextView
android:id="#+id/mywidget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:singleLine="true"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:textColor="#ff4500"
android:text="Simple application that shows how to use marquee, with a long text" />
I have an AutoCompleteTextView in my XML file:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<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"
tools:context="com.android.aashima.premiumpoint.PremiumPoint">
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/searchByName"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:padding="10dp"
android:background="#ddd"
android:hint="Search By Name"
android:textColorHint="#fff"
android:gravity="center"
android:layout_alignTop="#+id/searchImageButton"
android:layout_alignBottom="#+id/searchImageButton"
android:layout_toLeftOf="#+id/searchImageButton"
android:textColor="#fff"
android:completionThreshold="1"
android:imeOptions="actionDone"
android:dropDownWidth="fill_parent"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/searchImageButton"
android:src="#drawable/search40"
android:layout_alignParentRight="true"
android:padding="2dp"
android:background="#color/material_blue_grey_950"/>
</RelativeLayout>
I don't want it to gain focus when my Activity starts.
I tried giving the following to the parent layout:
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
giving a dummy item just above my AutoCompleteTextView:
<!-- Dummy item to prevent AutoCompleteTextView from receiving focus -->
<LinearLayout
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="0px"
android:layout_height="0px"/>
and setting:
android:nextFocusUp="#id/searchByName"
android:nextFocusLeft="#id/searchByName"
to AutoCompleteTextView .
On searching I found results similar to:
android:windowSoftInputMode="stateHidden"
android:windowSoftInputMode="stateUnchanged"
but what I want is prevent it from getting focus and not hiding the keypad from appearing.
I've tried many alternatives with no luck. Am I doing something wrong here?
Thanks in advance.
EDIT:
Also attempted:
clearFocus();
requestFocus();
Try combining 2 of your methods as follows:
<!-- Dummy item to prevent AutoCompleteTextView from receiving focus -->
<LinearLayout
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="0px"
android:layout_height="0px"/>
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/searchByName"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:padding="10dp"
android:background="#ddd"
android:hint="Search By Name"
android:textColorHint="#fff"
android:gravity="center"
android:layout_alignTop="#+id/searchImageButton"
android:layout_alignBottom="#+id/searchImageButton"
android:layout_toLeftOf="#+id/searchImageButton"
android:textColor="#fff"
android:completionThreshold="1"
android:imeOptions="actionDone"
android:dropDownWidth="fill_parent"
android:nextFocusUp="#id/searchByName"
android:nextFocusLeft="#id/searchByName"/>
Now, bring the dummy View and your AutoCompleteTextView to your java code and use:
dummy.requestFocus();
search.clearFocus();
and vice versa as and when you require.
I'm trying to get the following ScrollView to shrink down so that all the other elements above it will still be visible when using the IME, or, at the very least, so that the top of the ScrollView is moved down to the top of the screen.
Main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="match_parent"
android:orientation="vertical" android:id="#+id/gameLayout">
<TextView android:id="#+id/gameTitle" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:textColor="#color/Red"
android:maxLines="1" />
<ScrollView android:id="#+id/gameScroll"
android:layout_width="match_parent" android:layout_height="fill_parent"
android:fillViewport="false" android:layout_above="#+id/gameEntry"
android:layout_below="#+id/gameTitle">
<TextView android:id="#+id/gameText" android:layout_width="match_parent"
android:layout_height="wrap_content" android:scrollbars="vertical" />
</ScrollView>
<AutoCompleteTextView android:id="#+id/gameEntry"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" android:layout_toLeftOf="#+id/gameSubmit"
android:hint="#string/Hint" android:imeOptions="actionDone"
android:lines="1" />
<TextView android:id="#+id/gameSubmit" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignBaseline="#+id/gameEntry"
android:layout_alignParentRight="true" android:gravity="center"
android:text="#string/Submit" android:textColor="#color/Red"
android:textSize="18dp" android:lines="1" />
</RelativeLayout>
Can this be done?
I probably made some stupid mistake... Oh, I did everything they recommended on How to prevent that the keyboard hides my EditText?
And, I also added android:windowSoftInputMode="adjustResize" to the manifest, and it's still panning... Cue the "wow that's a silly question" in 3..2..1......
Try changing the android:layout_height="fill_parent" on the ScrollView to android:layout_height="wrap_content" and adding android:layout_above="#+id/gameEntry" to the ScrollView.
I have strange problem with TextView, it cuts off part of the text at the end. My layout looks like
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top|center_horizontal"
android:gravity="top|center_horizontal"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top|center_horizontal"
android:gravity="top|center_horizontal"
android:orientation="horizontal"
android:layout_weight="1"
android:layout_marginBottom="5dp">
<Button
android:id="#+id/btnPreviousQuestion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/selector_arrow_left"
android:clickable="true"
android:visibility="gone" >
</Button>
<TextView
android:id="#+id/txtQuestion"
style="#style/question_text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="top|center_horizontal"
android:layout_weight="1"
/>
<Button
android:id="#+id/btnNextQuestion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:background="#drawable/selector_arrow_right"
android:clickable="true" >
</Button>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:orientation="horizontal" >
<WebView
android:id="#+id/wvMultimediaQuestion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginLeft="50dp"
android:layout_marginRight="55dp"
android:layout_weight="1"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
and txtQuestion cuts off text when it is long enough. What is wrong, does anybody know ?
Make use of these attributes
android:lines="1"
android:scrollHorizontally="true"
android:ellipsize="end"
will append "..." at the end. But this will not solve problem in honeycomb tab
So for honeycomb tablet add the following atttibute also
android:singleLine="true"
On the other hand if you require marquee effect
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true
Yes there are some attributes you need to set, but first let us know what type of textview do you want exactly, single line or multi line?
There are some attributes you can take care of:
android:singleLine="true" // or false
android:ellipsize="marquee" // must check
android:lines="1"
Set below properties in layout file. It works fine for me
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:focusableInTouchMode="true"
If you expect differing lengths of text for your view or you're going to change the textSize of different instances of your TextView then you should use View.addOnLayoutChangeListener().
See an example here: https://stackoverflow.com/a/44069734/1402087
Set the layout_gravity on the TextView to fill
You need to set
android:minLines="2"
For me it I realised I was using the layout view of a different device to the one I was testing with. When I corrected this, I could see the textlayout was way too wide so I used this setting to reign it in:
android:layout_width="330dp"
Tried all the solutions provided here but none of these helps, finally got the solution using android:layout_width="0dp" instead of android:layout_width="fill_parent" in textview.
I want to marquee the textview but am not getting success to do it properly. Though i have gone through some examples give in stackoverflow, but still having problem. can anybody help?
try this it is working for me
<TextView
android:text="Android Marquee"
android:id="#+id/MarqueeText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:paddingLeft="15dip"
android:paddingRight="15dip"
android:focusable="true"
android:focusableInTouchMode="true"
android:freezesText="true">
</TextView>
It is the minimum code to create a marque -
<?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="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/MarqueeText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="This is a very long text which is not fitting in the screen so it needs to be marqueed."
android:textAppearance="?android:attr/textAppearanceLarge" />
To make your marque more presentable view this:
http://yhisham.blogspot.in/2012/08/android-how-to-make-marquee-ticker.html