我是android程序的新手。我想做一个有闪存卡的应用程序。这些闪存卡会有单词,当我触摸它们时,它会显示单词的含义。
我搜索了谷歌。但我找不到制作闪存卡的适当教程。
谢谢!
发布于 2017-06-21 14:21:26
欢迎来到Android Richa。
我为你找到了一些有用的链接:
基本上,您将使用动画和ImageViews。在列表中,你要做的最好的链接是“翻转动画解释”。
您将设置您的卡片的布局,然后活动。一旦准备就绪,您将在XML中制作动画。
我在这里找到了密码:
主活性
public class MainActivity extends AppCompatActivity {
private AnimatorSet mSetRightOut;
private AnimatorSet mSetLeftIn;
private boolean mIsBackVisible = false;
private View mCardFrontLayout;
private View mCardBackLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViews();
loadAnimations();
changeCameraDistance();
}
private void changeCameraDistance() {
int distance = 8000;
float scale = getResources().getDisplayMetrics().density * distance;
mCardFrontLayout.setCameraDistance(scale);
mCardBackLayout.setCameraDistance(scale);
}
private void loadAnimations() {
mSetRightOut = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.out_animation);
mSetLeftIn = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.in_animation);
}
private void findViews() {
mCardBackLayout = findViewById(R.id.card_back);
mCardFrontLayout = findViewById(R.id.card_front);
}
public void flipCard(View view) {
if (!mIsBackVisible) {
mSetRightOut.setTarget(mCardFrontLayout);
mSetLeftIn.setTarget(mCardBackLayout);
mSetRightOut.start();
mSetLeftIn.start();
mIsBackVisible = true;
} else {
mSetRightOut.setTarget(mCardBackLayout);
mSetLeftIn.setTarget(mCardFrontLayout);
mSetRightOut.start();
mSetLeftIn.start();
mIsBackVisible = false;
}
}
}您正在扰乱相机的距离在这里,以确保翻转动画在屏幕上看到。因为它可能越过“虚拟线”,根本看不见。
卡前端XML
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tint="@color/cardFront"
android:padding="16dp"
android:src="@drawable/rectangle"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/front"
android:textColor="@color/white"
style="@style/Base.TextAppearance.AppCompat.Display1"
android:gravity="center"/>
</FrameLayout>卡回XML
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tint="@color/cardBack"
android:padding="16dp"
android:src="@drawable/rectangle"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/back"
android:textColor="@color/white"
style="@style/Base.TextAppearance.AppCompat.Display1"
android:gravity="center"/>
</FrameLayout>活动XML
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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="blog.droidsonroids.pl.blogpost.MainActivity"
android:onClick="flipCard">
<FrameLayout
android:id="@+id/card_back"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/card_back" />
</FrameLayout>
<FrameLayout
android:id="@+id/card_front"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<include layout="@layout/card_front" />
</FrameLayout>
</FrameLayout>动画中的 XML
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:valueFrom="1.0"
android:valueTo="0.0"
android:propertyName="alpha"
android:duration="0" />
<objectAnimator
android:valueFrom="-180"
android:valueTo="0"
android:propertyName="rotationY"
android:repeatMode="reverse"
android:duration="@integer/anim_length" />
<objectAnimator
android:valueFrom="0.0"
android:valueTo="1.0"
android:propertyName="alpha"
android:startOffset="@integer/anim_length_half"
android:duration="0" />
</set>Out动画
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:valueFrom="0"
android:valueTo="180"
android:propertyName="rotationY"
android:duration="@integer/anim_length" />
<objectAnimator
android:valueFrom="1.0"
android:valueTo="0.0"
android:propertyName="alpha"
android:startOffset="@integer/anim_length_half"
android:duration="0" />
</set>https://stackoverflow.com/questions/44678501
复制相似问题