Question

I have a Button with text written on it, this text may be large so that it won't fit in the Button Width, So, that I want that text to be animated Horizontally in that Button, and if possible I need it to be Animated in a specific part of the Button as the other part will be occupied by the Button Background image:

enter image description here

And this is the problem:

enter image description here

And the solution I want to apply:

enter image description here enter image description here

And this is what i had try but didn't work:

<Button
    android:id="@+id/button1"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:layout_gravity="center"
    android:adjustViewBounds="true"
    android:layout_margin="3dp"
    android:gravity="left"
    android:background="@drawable/bg"
    android:textAlignment="center"
    android:text="Text Here Is Large"
    android:scrollHorizontally="true"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    android:lines="1"
    android:textSize="14sp"
    android:textColor="@android:color/white"
    android:paddingBottom="5dp"
    android:paddingLeft="3dp"
    android:paddingRight="3dp"
    android:paddingTop="5dp"
    android:clickable="true"
    android:tag="tag1" />
Was it helpful?

Solution 3

well, I solved it by putting the Button with a customized TextView together in a FrameLayout, this customized TextView is got from Here, and the following is how I made it:

<FrameLayout
  android:layout_width="match_parent"
  android:layout_height="0dp"
  android:layout_margin="3dp"
  android:layout_weight="1" >

  <Button
    android:id="@+id/button1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:adjustViewBounds="true"
    android:background="@drawable/some_image"
    android:clickable="true"
    android:tag="button1_tag" />

  <com.example.ScrollingTextView
    android:id="@+id/button1_name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:lines="1"
    android:marqueeRepeatLimit="marquee_forever"
    android:paddingBottom="5dp"
    android:paddingLeft="2dp"
    android:paddingRight="26dp"
    android:paddingTop="3dp"
    android:singleLine="true"
    android:text="zone1"
    android:textColor="@android:color/white"
    android:textSize="14sp" />

</FrameLayout>

OTHER TIPS

Adding the following line should make the marquee effect work:

android:singleLine="true"

If a button have focus, marquee will run.

Important:

android:singleLine=”true”
android:ellipsize=”marquee”

Optional:

android:marqueeRepeatLimit=”1″

in XML:

 <Button
    android:layout_width="150dip" 
    android:layout_height="wrap_content"
    android:text="My button with a long text for marquee as a example source code"
    android:singleLine="true"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="1"/>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top