我正在尝试开发一个应用程序,使用户可以学习新单词来增加英语词汇。我想做的是,该应用程序将首先在卡片中显示该词(例如版式),然后单击该卡片即可翻转背面将包含该单词的定义和示例。 我在互联网上搜索它,发现有一个库可以做到这一点,但问题是在使用该库后,滚动视图不起作用,因为要显示很多单词,所以滚动视图必须起作用。 这是我的布局代码,其中包含卡片的正面和背面:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:gravity="center"
android:orientation="vertical"
android:background="@color/grey"
>
<!-- This is what i found from the internet.
This made my screen non scrollable and also
the flip action was very poor(have to wait
alot for card to flip after it is clicked )
<com.wajahatkarim3.easyflipview.EasyFlipView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:flipOnTouch="true"
app:flipDuration="500"
app:flipEnabled="true"
>
</com.wajahatkarim3.easyflipview.EasyFlipView>
-->
<LinearLayout
android:id="@+id/back"
android:layout_width="300dp"
android:layout_height="400dp"
android:layout_gravity="center"
android:layout_marginTop="50dp"
android:orientation="vertical"
android:background="#fff"
android:gravity="center_horizontal">
<TextView
android:layout_marginTop="20dp"
android:id="@+id/word"
android:text=""
android:textSize="25dp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:gravity="center"
android:layout_marginTop="30dp"
android:text=""
android:textSize="25dp"
android:id="@+id/definition"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:gravity="center"
android:layout_marginTop="40dp"
android:text=""
android:textSize="25dp"
android:id="@+id/example"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="@+id/front"
android:layout_width="300dp"
android:layout_height="400dp"
android:layout_gravity="center"
android:layout_marginTop="50dp"
android:orientation="vertical"
android:background="#fff"
android:gravity="center_horizontal">
<ImageView
android:layout_marginLeft="120dp"
android:src="@drawable/ic_favorite_black_24dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/wordtext"
android:text=""
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
android:textSize="40sp" />
</LinearLayout>
</RelativeLayout>
这是显示此卡的java类:
package com.sandesh.wordapp;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.util.ArrayList;
public class AfterloginActivity extends AppCompatActivity {
LinearLayout container;
Databasehelper databasehelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_afterlogin);
container=findViewById(R.id.container);
databasehelper=new Databasehelper(this);
displayword_info();
}
@Override
protected void onResume() {
super.onResume();
displayword_info();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.afterloginmenu,menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id=item.getItemId();
switch(id)
{
case R.id.addwords:
Intent i=new
Intent(AfterloginActivity.this,AddwordActivity.class);
startActivity(i);
}
return super.onOptionsItemSelected(item);
}
public void displayword_info()
{
container.removeAllViews();
ArrayList<WordInfo> list=databasehelper.getword_info();
for(int i=0;i<list.size();i++)
{
WordInfo info=list.get(i);
View view=
LayoutInflater.from(this).inflate(R.layout.wordslayout,null);
TextView wordfront=view.findViewById(R.id.wordtext),
wordback=view.findViewById(R.id.word),
definition=view.findViewById(R.id.definition),
example=view.findViewById(R.id.example);
final LinearLayout front=findViewById(R.id.rl);
wordfront.setText(info.word);
wordback.setText(info.word);
definition.setText(info.definition);
example.setText(info.example);
container.addView(view);
}
}
}