【发布时间】:2020-05-27 23:11:24
【问题描述】:
我最近遇到了这个库。
https://github.com/DanielMartinus/Konfetti
我尝试在我的应用程序中实现它。我阅读了文档并尝试实现它。以下是我的代码:
JAVA 文件:
final KonfettiView konfettiView = findViewById(R.id.viewConfetti);
konfettiView.build()
.addColors(Color.YELLOW, Color.GREEN, Color.MAGENTA)
.setDirection(0.0, 359.0)
.setSpeed(1f, 5f)
.setFadeOutEnabled(true)
.setTimeToLive(2000L)
.addShapes(Shape.Square.INSTANCE, Shape.Circle.INSTANCE)
.addSizes(new Size(12, 5))
.setPosition(-50f, konfettiView.getWidth() + 50f, -50f, -50f)
.streamFor(300, 1500L);
下面是我的布局文件:
<?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:background="@drawable/folk"
tools:context=".TrueActivity">
<nl.dionsegijn.konfetti.KonfettiView
android:id="@+id/viewConfetti"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/CongoText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/congratulations"
android:visibility="invisible"
android:textSize="35dp"
android:textColor= "#FFF"
android:gravity="center"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
对我来说一切都很好。但五彩纸屑仅从左上角弹出。我试图将KonfettiView 对象更改为不同的尺寸(即尝试更改X-axis);但无济于事。我什至阅读了下面关于堆栈溢出的答案。
https://stackoverflow.com/a/46016959/13627957
但这似乎没有帮助。 有什么方法可以让它从主库readme file 中显示的完全顶部弹出,而不是只在左上角弹出。
谢谢。
【问题讨论】: