2016-12-20 5 views
0

ist es möglich, dass es mit Animation zu tun?Wie kann ich Edittext wie Google Übersetzer wechseln, wenn ich die Umschalttaste drücke?

fand ich auf Google textview switcher aber ich will edittext

ich so tun möchte, wechseln:

enter image description here

Dank im Voraus.

+0

, wenn Sie nur die Position tauschen wollen von zwei EditTexts, dann verwenden Sie einfach TransitionManager.beginDelayedTransition() 'und ändern die Position dieser beiden EditTexte, wahrscheinlich durch Ändern seiner LayoutParams. Stellen Sie sicher, dass Sie die Support-Bibliothek verwenden, damit sie in Versionen vor KitKat funktioniert. Stellen Sie außerdem sicher, dass beide EditTexts richtige IDs haben. –

Antwort

2

Kann dies Ihnen helfen kann, ..

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/linMain" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:weightSum="2" 
    tools:context="com.app.edittextswitch.MainActivity"> 


    <EditText 
     android:id="@+id/edit1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:background="@android:drawable/editbox_background_normal" /> 

    <ImageView 
     android:id="@+id/imgView" 
     android:layout_width="30dp" 
     android:layout_height="30dp" 
     android:layout_marginLeft="5dp" 
     android:layout_marginRight="5dp" 
     android:background="@drawable/arrow" /> 

    <EditText 
     android:id="@+id/edit2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:background="@android:drawable/editbox_background_normal" /> 


</LinearLayout> 

MainActivity.java:

public class MainActivity extends AppCompatActivity { 

    EditText edit1, edit2; 
    ImageView imgView; 
    Animation slide_in_left, slide_out_right; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     imgView = (ImageView) findViewById(R.id.imgView); 
     edit1 = (EditText) findViewById(R.id.edit1); 
     edit2 = (EditText) findViewById(R.id.edit2); 

     slide_in_left = AnimationUtils.loadAnimation(this, 
       android.R.anim.slide_in_left); 
     slide_out_right = AnimationUtils.loadAnimation(this, 
       android.R.anim.slide_out_right); 


     imgView.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 


       String text1 = edit1.getText().toString(); 
       String text2 = edit2.getText().toString(); 

       edit1.setText(text2); 
       edit2.setText(text1); 

       edit1.startAnimation(slide_out_right); 
       edit2.startAnimation(slide_out_right); 

      } 
     }); 
    } 


} 
Verwandte Themen