Reputation: 51
I have been working on an app for a while, which is in production on the store. At the last revision a problem appeared when running the app on a Samsung Galaxy 33A device. The problem does not show up on emulator nor on other Android devices.
Description of the issue
In a constraint layout, there is a horizontal linear layout with seven textViews containing numbers:
3, 4, ...9
in standard sans-serif font. Beside there is an imageView extending over the range of the linear layout and also one textView containing the letter M
. The linear layout has an elevation of 5dp to stay visible in front of the image view.
The purpose of the view is to let the user select a range of numbers by adjusting the length of the image view with the finger. Here is what it looks like on emulators and for example on a Xiaomi HyperOS for example:
And here is what it looks like on the Samsung Galaxy 33A. The numbers do not show up:
Does anyone know of such a bug specific to Samsung devices ? What would be the recommandation to solve such an issue ? Thanks for any advice.
XML xode of the layout:
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/plageEtCartouche"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="16dp">
<LinearLayout
android:id="@+id/plageNombreLettres"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:elevation="5dp"
android:gravity="start"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/tv3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="1"
android:gravity="center"
android:includeFontPadding="false"
android:text="3"
android:textColor="@android:color/black"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tv4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="1"
android:gravity="center"
android:includeFontPadding="false"
android:text="4"
android:textColor="@android:color/black"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tv5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="1"
android:gravity="center"
android:includeFontPadding="false"
android:text="5"
android:textColor="@android:color/black"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tv6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="1"
android:gravity="center"
android:includeFontPadding="false"
android:text="6"
android:textColor="@android:color/black"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tv7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="1"
android:gravity="center"
android:includeFontPadding="false"
android:text="7"
android:textColor="@android:color/black"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tv8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="1"
android:gravity="center"
android:includeFontPadding="false"
android:text="8"
android:textColor="@android:color/black"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tv9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="1"
android:gravity="center"
android:includeFontPadding="false"
android:text="9"
android:textColor="@android:color/black"
android:textSize="24sp"
android:textStyle="bold" />
</LinearLayout>
<ImageView
android:id="@+id/cartouche"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="160dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/cartouche" />
<TextView
android:id="@+id/btnMono"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="1"
android:fontFamily="cursive"
android:gravity="center"
android:includeFontPadding="false"
android:text="M"
android:textColor="@android:color/black"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/plageNombreLettres"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Fragment
And by the way, in the Fragment there is a few lines of code to adjust the size of the textViews and imageView to fit he size of the screen:
private fun initConstraints() {
pasNombre = (largeurEcran - 56.dp) / 10
for (view in binding.plageNombreLettres) {
view.updateLayoutParams<LinearLayout.LayoutParams> {
width = pasNombre
}
}
binding.plageEtCartouche.updateLayoutParams<LinearLayout.LayoutParams> {
height = pasNombre
}
val startCons = filtre.lMin.start
val endCons = filtre.lMax.end
binding.cartouche.updateLayoutParams<ConstraintLayout.LayoutParams> {
marginStart = startCons
marginEnd = endCons
}
}
Upvotes: 0
Views: 20
Reputation: 51
I managed to solve the problem by kind of coming back to the previous version that had worked before : I put the M
textView into the linearLayout with one empty textView on each side (to center it in the remain space without expanding it).
I also had to update the loop for sizing the numbers in the Fragment.
And now it works on Samsung Galaxy as well. Don't ask me why !
I must say I also upgraded a few dependencies in the build.gradle.kts
that were not up-to-date, like:
implementation("androidx.constraintlayout:constraintlayout:2.2.0")
Corrected XML
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/plageEtCartouche"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="16dp">
<LinearLayout
android:id="@+id/plageNombreLettres"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:elevation="5dp"
android:gravity="start"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/tv3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="1"
android:gravity="center"
android:includeFontPadding="false"
android:text="3"
android:textColor="@android:color/black"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tv4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="1"
android:gravity="center"
android:includeFontPadding="false"
android:text="4"
android:textColor="@android:color/black"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tv5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="1"
android:gravity="center"
android:includeFontPadding="false"
android:text="5"
android:textColor="@android:color/black"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tv6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="1"
android:gravity="center"
android:includeFontPadding="false"
android:text="6"
android:textColor="@android:color/black"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tv7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="1"
android:gravity="center"
android:includeFontPadding="false"
android:text="7"
android:textColor="@android:color/black"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tv8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="1"
android:gravity="center"
android:includeFontPadding="false"
android:text="8"
android:textColor="@android:color/black"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tv9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="1"
android:gravity="center"
android:includeFontPadding="false"
android:text="9"
android:textColor="@android:color/black"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="@+id/empty1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="1"
android:gravity="center"
android:includeFontPadding="false"
android:textColor="@android:color/black"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="@+id/btnMono"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="1"
android:fontFamily="cursive"
android:gravity="center"
android:includeFontPadding="false"
android:text="M"
android:textColor="@android:color/black"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="@+id/empty2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="1"
android:gravity="center"
android:includeFontPadding="false"
android:textColor="@android:color/black"
android:textSize="24sp"
android:textStyle="bold" />
</LinearLayout>
<ImageView
android:id="@+id/cartouche"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="160dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/cartouche" />
</androidx.constraintlayout.widget.ConstraintLayout>
Updated loop in the Fragment
private fun initConstraints() {
pasNombre = (largeurEcran - 56.dp) / 10
for (index in 0..<(binding.plageNombreLettres.childCount - 3)) {
val view = binding.plageNombreLettres.getChildAt(index)
view.updateLayoutParams<LinearLayout.LayoutParams> {
width = pasNombre
}
}
binding.plageEtCartouche.updateLayoutParams<LinearLayout.LayoutParams> {
height = pasNombre
}
val startCons = filtre.lMin.start
val endCons = filtre.lMax.end
binding.cartouche.updateLayoutParams<ConstraintLayout.LayoutParams> {
marginStart = startCons
marginEnd = endCons
}
}
Upvotes: 0