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"> <declare-styleable name="LocationLiveEndedBannerView">
<attr name="locLiveEndedBkgWithAlpha" format="boolean" /> <attr name="locLiveEndedBkgWithAlpha" format="boolean" />
<attr name="locLiveEndedIconMarginStart" format="dimension" />
</declare-styleable> </declare-styleable>
</resources> </resources>

View file

@ -21,6 +21,7 @@ import android.content.res.TypedArray
import android.util.AttributeSet import android.util.AttributeSet
import android.view.LayoutInflater import android.view.LayoutInflater
import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.updateLayoutParams
import im.vector.app.R import im.vector.app.R
import im.vector.app.databinding.ViewLocationLiveEndedBannerBinding import im.vector.app.databinding.ViewLocationLiveEndedBannerBinding
@ -44,6 +45,7 @@ class LocationLiveEndedBannerView @JvmOverloads constructor(
).run { ).run {
try { try {
setBackgroundAlpha(this) setBackgroundAlpha(this)
setIconMarginStart(this)
} finally { } finally {
recycle() recycle()
} }
@ -54,4 +56,11 @@ class LocationLiveEndedBannerView @JvmOverloads constructor(
val withAlpha = typedArray.getBoolean(R.styleable.LocationLiveEndedBannerView_locLiveEndedBkgWithAlpha, false) val withAlpha = typedArray.getBoolean(R.styleable.LocationLiveEndedBannerView_locLiveEndedBkgWithAlpha, false)
binding.locationLiveEndedBannerBackground.alpha = if (withAlpha) 0.75f else 1f 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:layout_gravity="bottom"
android:visibility="gone" android:visibility="gone"
app:locLiveEndedBkgWithAlpha="false" app:locLiveEndedBkgWithAlpha="false"
app:locLiveEndedIconMarginStart="16dp"
tools:visibility="visible" /> tools:visibility="visible" />
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

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