Adding attribute to set the start margin of icon

This commit is contained in:
Maxime NATUREL 2022-07-25 14:17:07 +02:00
parent e51488bc57
commit e1ea10e0a2
4 changed files with 13 additions and 1 deletions

View File

@ -3,6 +3,7 @@
<declare-styleable name="LocationLiveEndedBannerView">
<attr name="locLiveEndedBkgWithAlpha" format="boolean" />
<attr name="locLiveEndedIconMarginStart" format="dimension" />
</declare-styleable>
</resources>

View File

@ -21,6 +21,7 @@ import android.content.res.TypedArray
import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.updateLayoutParams
import im.vector.app.R
import im.vector.app.databinding.ViewLocationLiveEndedBannerBinding
@ -44,6 +45,7 @@ class LocationLiveEndedBannerView @JvmOverloads constructor(
).run {
try {
setBackgroundAlpha(this)
setIconMarginStart(this)
} finally {
recycle()
}
@ -54,4 +56,11 @@ class LocationLiveEndedBannerView @JvmOverloads constructor(
val withAlpha = typedArray.getBoolean(R.styleable.LocationLiveEndedBannerView_locLiveEndedBkgWithAlpha, false)
binding.locationLiveEndedBannerBackground.alpha = if (withAlpha) 0.75f else 1f
}
private fun setIconMarginStart(typedArray: TypedArray) {
val margin = typedArray.getDimensionPixelOffset(R.styleable.LocationLiveEndedBannerView_locLiveEndedIconMarginStart, 0)
binding.locationLiveEndedBannerIcon.updateLayoutParams<MarginLayoutParams> {
marginStart = margin
}
}
}

View File

@ -56,6 +56,7 @@
android:layout_gravity="bottom"
android:visibility="gone"
app:locLiveEndedBkgWithAlpha="false"
app:locLiveEndedIconMarginStart="16dp"
tools:visibility="visible" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -22,7 +22,8 @@
app:layout_constraintBottom_toBottomOf="@id/locationLiveInactiveMap"
app:layout_constraintEnd_toEndOf="@id/locationLiveInactiveMap"
app:layout_constraintStart_toStartOf="@id/locationLiveInactiveMap"
app:locLiveEndedBkgWithAlpha="true" />
app:locLiveEndedBkgWithAlpha="true"
app:locLiveEndedIconMarginStart="8dp" />
<ImageView
android:id="@+id/locationLiveInactiveIcon"