0
是否有可能與動畫?當我按下切換按鈕時,如何切換Google Translate等編輯文字?
我對谷歌textview switcher
找到,但我想改用edittext
我想做的事情是這樣的:
在此先感謝。
是否有可能與動畫?當我按下切換按鈕時,如何切換Google Translate等編輯文字?
我對谷歌textview switcher
找到,但我想改用edittext
我想做的事情是這樣的:
在此先感謝。
可能這可以幫助你..
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);
}
});
}
}
如果你只是想換位置的兩個EditTexts,然後你只需使用'TransitionManager.beginDelayedTransition()'並改變這兩個EditText的位置,可能通過更改其LayoutParams。確保使用支持庫使其在KitKat前版本中工作。同時確保這兩個EditText都有適當的ID。 –