Android TextView在可见性更改后丢失Alpha信息(当animateLayoutChange为true时)
当为我的布局启用了Android TextView在可见性更改后丢失Alpha信息(当animateLayoutChange为true时),android,android-layout,kotlin,material-design,Android,Android Layout,Kotlin,Material Design,当为我的布局启用了android:animateLayoutChanges时,我将组可见性更改为GONE,并将其恢复为VISIBLE时,TextView的alpha将重置为1 <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:alpha="0.2" android:
android:animateLayoutChanges
时,我将组可见性更改为GONE
,并将其恢复为VISIBLE
时,TextView的alpha将重置为1
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="0.2"
android:padding="16dp"
android:text="TextView"
android:textAppearance="@style/TextAppearance.MaterialComponents.Body2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.Group
android:id="@+id/group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="textView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
另外,我还尝试直接设置TextView可见性,同样的问题也会发生:
textView.visibility = if (textView.visibility == View.VISIBLE) View.GONE else View.VISIBLE
这是一个错误吗?是的,这是因为“动画布局更改”基本上使用alpha属性来设置动画。但为什么它不将alpha返回到以前的值?它就是不这样。继续报告一个bug。尽管您可以解决此问题:配置要设置动画的对象的父视图组的
布局转换
,以使用您自己的动画制作程序来显示转换类型,并使用您想要的正确目标alpha。是,这是因为“动画布局更改”基本上使用alpha属性来设置动画。但为什么它不将alpha返回到以前的值呢?它只是没有。继续报告一个bug。尽管您可以解决这一问题:配置要设置动画的对象的父视图组的layoututtransition
,以使用自己的动画制作程序来显示transitionType,并使用所需的正确目标alpha。
textView.visibility = if (textView.visibility == View.VISIBLE) View.GONE else View.VISIBLE