android - 为什么我的五彩纸屑来自 Android 屏幕的角落
问题描述
我正在使用nl.dionsegijn.konfetti.KonfettiView
Daniel Martinus GitHub提供的。但是每当我来到这个包含五彩纸屑的屏幕时,五彩纸屑就会从角落里出来。
这是它的 activty.xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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:padding="20dp"
tools:context=".EndScreen"
tools:ignore="HardcodedText">
<nl.dionsegijn.konfetti.KonfettiView
android:id="@+id/viewKonfetti"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
<TextView
android:id="@+id/tvCongrats"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Well done, you got an acheivement"
android:textSize="30sp"
android:textColor="@color/white"
android:textAlignment="center"
android:fontFamily="@font/m_extrabolditalic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
现在这里是它的 Activity.kt 文件:
package com.appmania.guess_o_rama
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.graphics.Color
import android.widget.Toast
import nl.dionsegijn.konfetti.KonfettiView
import nl.dionsegijn.konfetti.models.Shape
import nl.dionsegijn.konfetti.models.Size
class EndScreen : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_end)
val konfetti = findViewById<KonfettiView>(R.id.viewKonfetti)
konfetti.build()
.addColors( Color.rgb(244, 195, 88))
.setDirection(0.0, 359.0)
.setSpeed(1f, 4f)
.setFadeOutEnabled(true)
.setTimeToLive(2000L)
.addShapes(Shape.RECT, Shape.CIRCLE)
.addSizes(Size(12))
.setPosition(-50f, konfetti.width + 50f, -50f, -50f)
.streamFor(300, 5000L) }
}
* 抱歉,它太大了 - 我不知道如何解决这个问题
我将不胜感激任何帮助。
解决方案
我建议您尝试不同的方向和位置值,直到您满意为止。
尝试改变方向和位置
konfetti.build()
.addColors( Color.rgb(244, 195, 88))
.setDirection(0.0, 0.0) // chnage this to set the direction
.setSpeed(1f, 4f)
.setFadeOutEnabled(true)
.setTimeToLive(2000L)
.addShapes(Shape.RECT, Shape.CIRCLE)
.addSizes(Size(12))
.setPosition(-50f, konfetti.width + 50f, -50f, -50f) // and change position from here
.streamFor(300, 5000L)
推荐阅读
- angular - 单元测试动态方法调用Angular
- github - 当我在 GitHub 上填写拉取请求表单时,如何链接问题?
- r - 在 r 中展开列并按 ID 计数
- javascript - a[x] && ax 有什么区别
- sql-server - 您可以在一个 SSMS 选项卡中并行运行 2 个 SQL 查询吗?
- node.js - 错误 TS2749:“IRequestWithUser”指的是一个值,但在这里被用作一种类型。您的意思是“typeof IRequestWithUser”吗?
- python - 在 Mac (OSX 10.15.6) 上使用 Python 打开和读取 .txt 文件时出现 Unicode 编码错误
- arrays - 在Excel中的一个单元格中制作数字数组
- macros - 错误地使用 dbt_utils.union_relations 但不知道如何/为什么?
- android - Kivy RecycleView - 图标复制并放置在数据项中