Skip to content

Instantly share code, notes, and snippets.

@cbedoy
Created November 18, 2019 03:11
Show Gist options
  • Select an option

  • Save cbedoy/982630cd455bd8529fb494bed41c2b0a to your computer and use it in GitHub Desktop.

Select an option

Save cbedoy/982630cd455bd8529fb494bed41c2b0a to your computer and use it in GitHub Desktop.
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="horizontal"
app:layout_constraintEnd_toStartOf="@+id/final_view"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:background="#999"
android:textColor="#FFF"
android:padding="8dp"
android:gravity="center|right"
android:id="@+id/initial_view"
android:layout_weight="40"
android:layout_width="wrap_content"
android:layout_height="match_parent"
tools:text="40"
tools:ignore="RtlHardcoded" />
<TextView
android:gravity="center"
android:id="@+id/counter_view"
android:layout_weight="60"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>
<TextView
android:background="#333"
android:textColor="#FFF"
android:padding="8dp"
android:gravity="center"
android:id="@+id/final_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
tools:text="100"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
private fun reload(current: Int){
val initialLayoutParams = initial_view.layoutParams as LinearLayout.LayoutParams
initialLayoutParams.weight = current.toFloat()
val counterLayoutParams = counter_view.layoutParams as LinearLayout.LayoutParams
counterLayoutParams.weight = (final - current).toFloat()
initial_view.layoutParams = initialLayoutParams
counter_view.layoutParams = counterLayoutParams
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment