Tôi có GridView
và tôi muốn animation
như cửa hàng Google Play. Trong đó, khi chúng ta nhấp vào bất kỳ ứng dụng nào thì nó sẽ chuyển hướng đến trang chi tiết của nó. Vào thời điểm đó, một hoạt ảnh nhỏ diễn ra. Tôi muốn loại hoạt ảnh này cho GridView
và trang chi tiết của nó. Tôi cần sự giúp đỡ nếu có ai đó biết về loại chuyển tiếp hoạt động này từ lớp này sang lớp khác.Hoạt ảnh hoạt động như cửa hàng Google Play
6
A
Trả lời
6
Đây là Đầu Mã hoạt động của bạn từ nơi bạn muốn di chuyển đến màn hình chi tiết
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.util.Pair;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
public class StartActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
}
public void onClick(View view) {
View imageView = findViewById(R.id.imageView);
View textView = findViewById(R.id.textView);
View button = findViewById(R.id.button);
Intent intent = new Intent(this, EndActivity.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
textView.setTransitionName(getString(R.string.activity_text_trans));
button.setTransitionName(getString(R.string.activity_mixed_trans));
Pair<View, String> pair1 = Pair.create(imageView, imageView.getTransitionName());
Pair<View, String> pair2 = Pair.create(textView, textView.getTransitionName());
Pair<View, String> pair3 = Pair.create(button, button.getTransitionName());
ActivityOptionsCompat options = ActivityOptionsCompat.
makeSceneTransitionAnimation(this, pair1, pair2, pair3);
startActivity(intent, options.toBundle());
}
else {
startActivity(intent);
}
}
}
Đây là màn hình chi tiết hoạt động
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
public class EndActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_end);
View smallImageView = findViewById(R.id.textView);
View editText = findViewById(R.id.editText);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
smallImageView.setTransitionName(getString(R.string.activity_text_trans));
editText.setTransitionName(getString(R.string.activity_mixed_trans));
}
}
}
tập tin FirstActivity layouut
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp">
<ImageView
android:id="@+id/imageView"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_centerHorizontal="true"
android:src="@drawable/aa_logo_green"
android:transitionName="@string/activity_image_trans"/>
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/imageView"
android:text="Simple TextView"
android:textSize="20sp"/>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/textView"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:text="Click Me"
style="@style/Widget.AppCompat.Button.Borderless"
android:onClick="onClick"/>
</RelativeLayout>
EndActivity xml file layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp">
<ImageView
android:id="@+id/imageView"
android:layout_width="220dp"
android:layout_height="220dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:src="@drawable/aa_logo_green"
android:transitionName="@string/activity_image_trans"/>
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:hint="An EditText"
android:textSize="24sp"/>
<ImageView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/imageView"
android:layout_alignBottom="@id/imageView"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:src="@drawable/aa_logo_blue"/>
</RelativeLayout>
1
Tôi nghĩ Bạn muốn giao dịch hoạt động chính xác vật chất, đọc developer doc here cũng cố gắng lib này cho Dịch animationhttps://github.com/lgvalle/Material-Animations
Các vấn đề liên quan
- 1. Google Chrome tắt hoạt ảnh cửa sổ
- 2. Tệp APK Android: Kích hoạt lại tệp APK cũ hơn trong Cửa hàng Google Play
- 3. Theo dõi chiến dịch trên cửa hàng Google Play không hoạt động với trình duyệt web cài đặt
- 4. 'meta name = "google-play-app"' có hoạt động không?
- 5. Triển khai tới Cửa hàng Google Play qua API
- 6. Hàng đợi.js hoạt động như thế nào?
- 7. Hoạt ảnh trên Android hoạt động như thế nào?
- 8. Đặt lại số phiên bản trên cửa hàng Google Play
- 9. Thu thập thông tin cửa hàng Google Play
- 10. Hộp thư đến Google như RecyclerView mục hoạt ảnh mở
- 11. Hoạt ảnh gợi ý NavigationDrawer (như Google Dòng tin)
- 12. Android: Hoạt ảnh động không hoạt động
- 13. iOS: springWithDamping giống như hoạt ảnh cho hoạt ảnh KeyFrame
- 14. Cửa hàng Connect-redis không hoạt động với socket.io
- 15. itunes cửa hàng hoạt động thất bại trong xcode 6
- 16. Thư viện hình ảnh như hình ảnh trên Google Play? (với xem hình ảnh tiếp theo)
- 17. Hoạt ảnh hiển thị CSS Hoạt động không hoạt động
- 18. Đóng cửa hoạt động như thế nào? (C#)
- 19. jQuery $ (cửa sổ) .load không hoạt động như mong đợi
- 20. Hàng chuyển động lập trình có hoạt ảnh trong UITableView
- 21. Tôi có cần android.permission.WAKE_LOCK cho Dịch vụ Google Play nếu tôi chỉ phát hành trong Cửa hàng Google Play không?
- 22. Google dfp pubads(). Refresh() không hoạt động như mong đợi
- 23. Mã Google Analytics, mã hoạt động như thế nào?
- 24. Google Indoor Navigation hoạt động như thế nào?
- 25. Google dự đoán API hoạt động như thế nào
- 26. Hoạt ảnh CSS3 không hoạt động Firefox
- 27. Hoạt ảnh UIViewController ngừng hoạt động
- 28. Hoạt ảnh xếp kề của Google Plus
- 29. độ trễ hoạt ảnh không hoạt động
- 30. RelativeLayout khiến hoạt ảnh không hoạt động?
Đây không phải là một "lib" . Đó là một lời giải thích về cách sử dụng [Android Transition Framework] của Google (https://developer.android.com/training/transitions/overview.html). Và nó tuyệt vời! –