0
我有四個按鈕,我希望文本切換器在選擇另一個按鈕時更改文本。對於我的切換臺,我希望文本位於按鈕視圖的中心,我想 想知道如何做到這一點,因爲我很難將文本置於按鈕 的中心。Android TextSwitcher以Android Button爲中心
我有四個按鈕,我希望文本切換器在選擇另一個按鈕時更改文本。對於我的切換臺,我希望文本位於按鈕視圖的中心,我想 想知道如何做到這一點,因爲我很難將文本置於按鈕 的中心。Android TextSwitcher以Android Button爲中心
TextSwitcher出動畫當前文字和動畫的新文本。在XML這樣
上創建
private TextSwitche mSwitcher = (TextSwitcher) findViewById(R.id.switcher);
mSwitcher.setFactory(this);
Button nextButton = (Button) findViewById(R.id.one);
nextButton.setOnClickListener(this);
和
public View makeView() {
Button b= new Button(this);
b.setGravity(Gravity.CENTER | Gravity.CENTER_HORIZONTAL);
b.setTextSize(70);
b.setTextColor(Color.RED);
return b;
}
<Button android:id="@+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="one"
android:textStyle="bold|italic" />
<Button android:id="@+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Switch"
android:textStyle="bold|italic" />
<TextSwitcher android:id="@+id/switcher"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
我還沒有測試過這個代碼,但我認爲它對你有幫助。如果你想了解更多關於textSwitcher的信息,請轉到Documentation。 和Android, make text switcher central?
好吧我打算給這個嘗試,因爲我有我的切換器和viewfactory設置,只是想了解如何將文本切換器中的文本居中按鈕視圖。 – Shakey 2012-01-11 14:24:15