기존 TextView가 있습니다 (코드 이름은 입니다.) 멋진 텍스트로 텍스트를 변경하고 싶습니다.Android - TextSwitcher - TextView 변경
텍스트를 변경하는 애니메이션을 만드는 유일한 방법은 TextSwitcher를 사용하는 것입니다.
이 코드 사용하려고:
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
내가 무엇을 할 수
quoteSwitcher = (TextSwitcher)findViewById(R.id.quote_switcher);
quoteSwitcher.addView(quote);
Animation in = AnimationUtils.loadAnimation(this,
android.R.anim.fade_in);
Animation out = AnimationUtils.loadAnimation(this,
android.R.anim.fade_out);
quoteSwitcher.setInAnimation(in);
quoteSwitcher.setOutAnimation(out);
quoteSwitcher.setText("Example text");
을 그리고이 코드에서 예외가 발생? 애니메이션으로 TextView 텍스트를 변경하기 만하면됩니다.
전체 코드 :
protected void initWidgets() {
quote = (TextView)findViewById(R.id.quote); // Афоризм
/* Начальное значение афоризма */
quote.setText(getRandomQuote());
/* Плавная анимация смены афоризмов */
quoteSwitcher = (TextSwitcher)findViewById(R.id.quote_switcher);
quoteSwitcher.removeAllViewsInLayout();
quoteSwitcher.addView(quote);
Animation in = AnimationUtils.loadAnimation(this,
android.R.anim.fade_in);
Animation out = AnimationUtils.loadAnimation(this,
android.R.anim.fade_out);
quoteSwitcher.setInAnimation(in);
quoteSwitcher.setOutAnimation(out);
quoteSwitcher.setText(getRandomQuote());
}
XML :
이<LinearLayout 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=".MainActivity"
android:orientation="vertical"
android:focusableInTouchMode="false"
android:id="@+id/main_layout">
<TextSwitcher
android:id="@+id/quote_switcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextSwitcher>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/logotype_layout">
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:id="@+id/logotype"
android:layout_gravity="center_horizontal"
android:src="@drawable/logotype"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/main_logotext"
android:id="@+id/logotext"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:textSize="55sp" />
<TextView
android:fontFamily="sans-serif-thin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/main_quote_0"
android:id="@+id/quote"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:textSize="15sp"
android:textStyle="italic" />
quoteSwitcher 해시 하위 항목이 quoteSwitcher.addView (quote) 전에 quoteSwitcher.removeView()를 호출하는지 확인해보십시오. –
확인 http://www.learn-android-easily.com/2013/06/android-textswitcher.html –
당신은 xml을 게시 할 수 있습니까 ?? –