2012-05-08 42 views
3

我想稍微移動當前按下的按鈕上的文字。在我的情況下,按鈕具有自定義背景,並且如果文本將被移動,則按鈕看起來會更好。如何在當前按下的按鈕上移動文本?

我做了兩個NinePath圖像不同的補白:

enter image description here

enter image description here

,並使用選擇設置它們:

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

    <item android:drawable="@drawable/btn_pressed" android:state_pressed="true"/> 
    <item android:drawable="@drawable/btn"/> 

</selector> 

這不起作用,文字遺蹟在按下按鈕時(和背景被交換)在它的位置上。

我的NinePath圖像可以嗎?有沒有辦法在沒有設置觸摸監聽器的情況下移動文本?

P.S.同樣的問題被問了,不過「答案」正是我試圖解決方案:https://stackoverflow.com/a/7677098/694770

回答

0

試試這個

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

    <item android:text="Pressed state text" android:state_pressed="true"/> 
    <item android:text="Default text"/> 

</selector> 
+0

它會導致異常,因爲您必須指定drawable。但即使它被定義爲文本沒有改變。我認爲選擇器只適用於drawable。 – Andrej

1

你的9片圖像好看。也就是說,我遇到了這個問題,因爲我有完全相同的問題,而且我的圖像也無法正常工作。

我結束了子類Button和弄髒填充。 More info here

相關問題