ConstraintLayoutのImageFilterViewって単体でも使えるんやなって

ConstraintLayout 2.0.0-alphaからImageFilterViewクラスが追加されました。今まで、MotionLayoutと一緒に使うものだから、使い所限られそうだなぁ〜と思っていたのですが、単体でも使えそうだったので、その報告記事になります。

この記事ではConstraintLayout 2.0.0-alpha4を使っています。

角丸にする

round属性から指定する事ができます。

<androidx.constraintlayout.utils.widget.ImageFilterView
  android:id="@+id/image"
  android:layout_width="100dp"
  android:layout_height="100dp"
  app:layout_constraintBottom_toBottomOf="parent"
  app:layout_constraintEnd_toEndOf="parent"
  app:layout_constraintStart_toStartOf="parent"
  app:layout_constraintTop_toTopOf="parent"
  app:round="0.5dp" />

彩度

saturation属性から設定することが出来ます。

<androidx.constraintlayout.utils.widget.ImageFilterView
  android:id="@+id/image"
  android:layout_width="100dp"
  android:layout_height="100dp"
  app:layout_constraintStart_toStartOf="parent"
  app:layout_constraintTop_toTopOf="parent"
  app:round="0.5dp"
  app:saturation="0.1" />

コントラスト

contrast属性から設定することが出来ます。

<androidx.constraintlayout.utils.widget.ImageFilterView
  android:id="@+id/image"
  android:layout_width="100dp"
  android:layout_height="100dp"
  app:contrast="0.5"
  app:layout_constraintStart_toStartOf="parent"
  app:layout_constraintTop_toTopOf="parent"
  app:round="0.5dp" />

暖色、寒色

warmth属性から、暖色、寒色?を設定することできます。

<androidx.constraintlayout.utils.widget.ImageFilterView
  android:id="@+id/image"
  android:layout_width="100dp"
  android:layout_height="100dp"
  app:layout_constraintStart_toStartOf="parent"
  app:layout_constraintTop_toTopOf="parent"
  app:round="0.5dp"
  app:warmth="2" />

<androidx.constraintlayout.utils.widget.ImageFilterView
  android:id="@+id/image"
  android:layout_width="100dp"
  android:layout_height="100dp"
  app:layout_constraintStart_toStartOf="parent"
  app:layout_constraintTop_toTopOf="parent"
  app:round="0.5dp"
  app:warmth="0.5" />

クロスフェード

crossfade属性から設定することが出来ます。ただ、この属性はMotionLayoutと一緒に使うもので、単体では使わないと思います。

まとめ

Written by
あんどろいどでぃべろっぱぁー🍎