2016-01-27 53 views
1

我是一個新的,當涉及到android編程。 我試圖做一個簡單的(現在)musicPlayer,當我在LandScape中顯示上下文時,我想從右端的文字動畫到textView最左邊的位置。這或多或少是屏幕的中心。 我有一個腳本,使動畫是:隱藏文本Out of TextView android Java

<translate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:duration="10000" 
    android:fromXDelta="100%" 
    android:interpolator="@android:anim/linear_interpolator" 
    android:repeatCount="infinite" 
    android:repeatMode="restart" 
    android:toXDelta="-100%" 
> 
</translate> 

OK,它的工作原理,當它是肖像,因爲我使用的屏幕上方的TextView的從右到左,因此文本可以在滑動整個屏幕。 現在說到LandScape,就像我之前說過的,我不希望文本在整個屏幕上滑動。

我想要做的是,當它到達TextView的最左邊的位置,它應該開始disapear ...

任何幫助...... 請

+0

您可以使用yourTextView.setVisibility(Visibility.GONE) –

+0

幫助表示讚賞,但我不想讓它消失。我只是不想顯示出來的textView,因爲它有一個無限的圓。每當它離開屏幕100%它再次從右側進來 –

回答

0

我想做的事是當到達TextView的最左邊 位置,它應該開始disapear ...

要做到這一點,你可以阿爾法過渡添加到您翻譯的動畫,這將導致文叔o在接近最左邊位置時淡出。這將是這個樣子:

<?xml version="1.0" encoding="utf-8"?> 
<set 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shareInterpolator="false"> 

<translate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:duration="10000" 
    android:fromXDelta="100%" 
    android:interpolator="@android:anim/linear_interpolator" 
    android:repeatCount="infinite" 
    android:repeatMode="restart" 
    android:toXDelta="-100%" /> 

<alpha 
    android:duration="10000" 
    android:fromAlpha="1.0" 
    android:toAlpha="0.0" /> 
</set> 

如果你不希望它開始淡出,直到它到達靠近邊緣,你可以加一個偏移量阿爾法塊這樣的:

android:startOffset="200"

這將導致alpha動畫直到參數時間結束(上述情況下爲200ms)纔開始。

+0

謝謝,它的工作部分(可能我沒有按照它應該的方式使用它)。如果淡出,但現在是什麼。我應該再次使用alpha過程,在它進入屏幕之前淡入它 –

+0

在動畫開始之前,您可以在'TextView'上調用'setAlpha(1.0)'來重置值。我認爲這應該適用於你想要做的事情。 – NoChinDeluxe

+0

有問題,當它開始淡出我去整個文本(textView的內容),我需要使它逐個字母,因爲它走出texta –

0

如果我們把這個代碼放在佈局文件中,它就能很好地工作。

android:singleLine="true" 
android:ellipsize="marquee" 
android:marqueeRepeatLimit ="marquee_forever" 
android:scrollHorizontally="true" 
android:focusable="true" 
android:focusableInTouchMode="true" 

AnyWayThanksForYourHelp