首先对任何英语不好对不起。 (不是我的母语)
我正在寻找按钮的动画,该动画在单击时会下降。
这是我的第一个观点。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingStart="30dp"
android:paddingTop="170dp"
android:paddingEnd="30dp"
tools:context=".MainActivity">
<Button
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/login"
android:onClick="login" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="register"
android:text="@string/register"
android:paddingTop="10dp" />
并且当我单击按钮时,另一个将消失(我知道如何)然后该视图将转换为第二个视图(在第一个视图下方)。
第二个视图:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingStart="30dp"
android:paddingTop="170dp"
android:paddingEnd="30dp"
tools:context=".MainActivity">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
app:errorEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="@+string/email"
android:inputType="textEmailAddress" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
app:errorEnabled="true"
app:passwordToggleEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="@+string/password"
android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/login"
android:onClick="login" />
如果我不太清楚,我也可以画出来。
感谢您的帮助!
您可以使用此:
将名称为(click_anim.xml)的动画资源文件创建到res的动画目录中:
click_anim.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha = "1.0"
android:toAlpha = "0.5"
android:duration = "100">
</alpha>
<scale
android:fromXScale = "1"
android:toXScale = "0.9"
android:fromYScale = "1"
android:toYScale = "0.9"
android:pivotX="50%"
android:pivotY="50%"
android:duration = "50">
</scale>
</set>
现在您可以对button
中的所有Textview
,activity
或...使用此动画
Button login = findViewById(R.id.login);
login .startAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.click_anim));