我有三个以上的活动,而其他活动过渡得很好,但是每次我导航到其中时,我包含以下代码的一个活动似乎都在跳跃。
我已经覆盖了动画类,但是跳转仍然持续。我该如何解决?我的Ui线程超载了吗?
public class ListActivity extends AppCompatActivity implements
RecyclerViewAdapter.OnItemClickListener {
RecyclerViewAdapter recyclerViewAdapter;
RecyclerView recyclerView;
private FirebaseFirestore db = FirebaseFirestore.getInstance();
private CollectionReference dbRef = db.collection("Archives");
Context context;
FloatingActionButton fab;
Item clickedItem;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
recyclerView = findViewById(R.id.recyclerView);
fab = findViewById(R.id.fab);
Toolbar toolbar = findViewById(R.id.toolbar);
if (toolbar != null) {
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
}
});
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(ListActivity.this,
EnterDataActivity.class);
startActivity(intent);
}
});
setUpAdapter();
}
private void setUpAdapter() {
Query query = dbRef.orderBy("fname", Query.Direction.DESCENDING);
FirestoreRecyclerOptions<Item> options = new
FirestoreRecyclerOptions.Builder<Item>()
.setQuery(query, Item.class)
.build();
recyclerViewAdapter = new RecyclerViewAdapter(options,
ListActivity.this);
recyclerViewAdapter.notifyDataSetChanged();
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(context));
recyclerView.setAdapter(recyclerViewAdapter);
recyclerViewAdapter.setOnItemClickListener(ListActivity.this);
}
@Override
public void onStart() {
super.onStart();
recyclerViewAdapter.startListening();
}
@Override
public void onStop() {
super.onStop();
recyclerViewAdapter.stopListening();
}
@Override public void onItemClick(DocumentSnapshot documentSnapshot, int
position) {
clickedItem = documentSnapshot.toObject(Item.class);
clickedItem.setId((documentSnapshot.getId()));
Intent intent = new Intent(ListActivity.this, DetailActivity.class);
intent.putExtra(First_Name, clickedItem.getFname());
intent.putExtra(Middle_Name, clickedItem.getMname());
intent.putExtra(Sur_Name, clickedItem.getSname());
intent.putExtra(Email, clickedItem.getEmail());
intent.putExtra(phone, clickedItem.getPhone());
intent.putExtra(city, clickedItem.getCity());
intent.putExtra(parents_Name, clickedItem.getParentsName());
intent.putExtra(parents_Phone, clickedItem.getParentsContact());
intent.putExtra(dob, clickedItem.getDob());
intent.putExtra(emergency, clickedItem.getEmergency());
intent.putExtra(profile_Picture, clickedItem.getProfilePicture());
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
startActivityForResult(intent, 45);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable
Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if ((requestCode == 45 && resultCode == RESULT_OK && data != null)) {
String fname = data.getStringExtra(First_Name);
String mname = data.getStringExtra(Middle_Name);
String sname = data.getStringExtra(Sur_Name);
String email = data.getStringExtra(Email);
String Phone = data.getStringExtra(phone);
String City = data.getStringExtra(city);
String pname = data.getStringExtra(parents_Name);
String pphone = data.getStringExtra(parents_Phone);
String Dob = data.getStringExtra(dob);
String Emergency = data.getStringExtra(emergency);
String profile = data.getStringExtra(profile_Picture);
Item items = new Item(fname, mname, sname, email, Phone, City,
pname, pphone, Dob, Emergency, profile);
db.collection("Archives").document(clickedItem.getId())
.set(items).addOnSuccessListener(new
OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Toast.makeText(ListActivity.this, "Updated Successfully",
Toast.LENGTH_LONG).show();
}
});
}
}
}
最佳答案
overridePendingTransition
的Activity文档说:
在startActivity(android.content.Intent)或finish()中的一种之后立即调用,以指定要执行的显式过渡动画。
因此,在其他任何地方调用overridePendingTransition
至少没有任何作用。删除此类呼叫,例如在ListActivity#onCreate
之后的setContentView
中,并将其放在startActivity
或startActivityForResult
的下一行。
关于java - 打开 Activity 时如何停止“跳跃效果”?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57115665/