TextView исчезает после перевода анимации из одного линейного в другое

Я пытаюсь обменять два текстовых представления (которые находятся в разных линейных макетах) друг с другом.

Мое требование мало похоже на упомянутое в ссылке ниже,

Анимация: переместить TextView в другой контейнер

Я использовал ObjectAnimator библиотеки "nineoldandroids", но текстовое представление исчезает, когда оно перемещается в другой макет.

Может кто-нибудь, пожалуйста, помогите мне в этом. Заранее спасибо.

Обновление 1: -

Теперь я использовал PropertyValuesHolder из библиотеки "nineoldandroids" для выполнения анимации перевода. После использования PropertyValuesHolder текстовое представление отображается (то есть не исчезает) после завершения анимации. Но функция анимации не работает после анимации.

Также я поместил сообщение с тостом, чтобы проверить размерность текстовых изображений после анимации.

Затем я получил следующие показы: - Перед анимацией: - для просмотра текста в первой строке и первом столбце (т.е. tv11):- 0.0 для просмотра текста во второй строке и во втором столбце (т.е. tv22):- 0.0

После анимации: - для просмотра текста в первой строке и первом столбце (т. Е. Tv11):- 240,0 для просмотра текста во второй строке и во втором столбце (т. Е. Tv22):- -240,0

Есть ли в любом случае, чтобы сделать эти текстовые представления как дочерние для других макетов (туда, где они были перемещены).

Пожалуйста, найдите ниже код для того же: -

  • MainActivity.java:-

    findViewById(R.id.tv22).setOnClickListener( new View.OnClickListener() {
            public void onClick(View v) {
    
                PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("x", +240);
                PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("y", +380);
                ObjectAnimator.ofPropertyValuesHolder(findViewById(R.id.tv11), pvhX, pvhY).setDuration(2000).start();
    
    
                PropertyValuesHolder pvhX2 = PropertyValuesHolder.ofFloat("x", -240);
                PropertyValuesHolder pvhY2 = PropertyValuesHolder.ofFloat("y", -380);
                ObjectAnimator.ofPropertyValuesHolder(findViewById(R.id.tv22), pvhX2, pvhY2).setDuration(2000).start();
                Toast.makeText(MainActivity.this, ((TextView)findViewById(R.id.tv11)).getX()+"tv11", Toast.LENGTH_SHORT).show();
                Toast.makeText(MainActivity.this, ((TextView)findViewById(R.id.tv22)).getX()+"tv22", Toast.LENGTH_SHORT).show();
    
            }
        });
    
  • activity_main.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"
    android:clipChildren="false"
    android:orientation="vertical"
    tools:context=".MainActivity" >
    <View
    android:layout_width="match_parent"
    android:layout_height="1dp" />
    
    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:clipChildren="false"
    android:orientation="horizontal" >
    
    <View
        android:layout_width="1dp"
        android:layout_height="match_parent" />
    
    <TextView
        android:id="@+id/tv11"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#4374E0" />
    
    <View
        android:layout_width="1dp"
        android:layout_height="match_parent" />
    
    <TextView
        android:id="@+id/tv13"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#4374E0" />
    
    <View
        android:layout_width="1dp"
        android:layout_height="match_parent" />
    </LinearLayout>
    
    <View
    android:layout_width="match_parent"
    android:layout_height="1dp" />
    
    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:clipChildren="false"
    android:orientation="horizontal" >
    
    <View
        android:layout_width="1dp"
        android:layout_height="match_parent" />
    
    <TextView
        android:id="@+id/tv21"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#4374E0" />
    
    <View
        android:layout_width="1dp"
        android:layout_height="match_parent" />
    
    <TextView
        android:id="@+id/tv22"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#4374E0" />
    
    <View
        android:layout_width="1dp"
        android:layout_height="match_parent" />
    </LinearLayout>
    
    <View
    android:layout_width="match_parent"
    android:layout_height="1dp" />
    
    </LinearLayout>
    
  • Обновление 2: -

Даже после внесения следующих изменений, onclick не работает нормально. Может ли кто-нибудь, пожалуйста, помогите мне.

        findViewById(R.id.tv22).setOnClickListener( new View.OnClickListener() {
            public void onClick(View v) {

                Toast.makeText(MainActivity.this, ((TextView)findViewById(R.id.tv11)).getX()+"tv11"+((TextView)findViewById(R.id.tv22)).getX()+"tv22", Toast.LENGTH_SHORT).show();                  

                PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("x", +240);
                PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("y", +380);
                final ObjectAnimator changeIn = ObjectAnimator.ofPropertyValuesHolder(findViewById(R.id.tv11), pvhX, pvhY).setDuration(2000);
                changeIn.addListener(new AnimatorListenerAdapter() {
                    public void onAnimationEnd(Animator anim) {                 
                        view.setScaleX(1f);
                        view.setScaleY(1f);*/                                                                                   
                        TextView testtv1= (TextView)findViewById(R.id.tv11);                            
                        TextView testtv2= (TextView)findViewById(R.id.tv22);
                        testtv1.clearAnimation();
                        testtv2.clearAnimation();
                        View v1= container1.getChildAt(1);
                        View v2= container2.getChildAt(3);
                        Log.i("childcount1 before",container1.getChildCount()+"");
                        container1.removeView(v1);
                        Log.i("childcount1 after",container1.getChildCount()+"");
                        Log.i("childcount2 before",container2.getChildCount()+"");
                        container2.removeView(v2);
                        Log.i("childcount2 after",container2.getChildCount()+"");
                        Log.i("check1","Removed Successfully");

                        LinearLayout.LayoutParams lp = new    LinearLayout.LayoutParams(0,0);
                        container1.addView(v2, 1,lp);                           
                        container2.addView(v1, 3,lp);

                        Toast.makeText(MainActivity.this, ((TextView)findViewById(R.id.tv11)).getX()+"tv11"+((TextView)findViewById(R.id.tv22)).getX()+"tv22", Toast.LENGTH_SHORT).show();

                    }
                });
                changeIn.start();

                PropertyValuesHolder pvhX2 = PropertyValuesHolder.ofFloat("x", -240);
                PropertyValuesHolder pvhY2 = PropertyValuesHolder.ofFloat("y", -380);
                ObjectAnimator.ofPropertyValuesHolder(findViewById(R.id.tv22), pvhX2, pvhY2).setDuration(2000).start();


            }
        });

0 ответов

Другие вопросы по тегам