Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – Overlapping items in RelativeLayout with ImageView and TextView

Posted on November 11, 2022 By

Solution 1 :

We have to give a Start and End for alignment instead of Left and Right because for multilanguage (localization) it won’t support.

Example:

    Case 1: In Arabic, Text starts from Right to Left

    Case 2: In English, Text starts from Left to Right

Changes in TextView:

Add these lines,

    android_textAlignment="center"
    android_layout_toEndOf="@+id/previous_button"
    android_layout_toStartOf="@+id/next_button"

Need to remove this Code in TextView,

    android_layout_centerHorizontal="true"

Full sample code try this,

    <RelativeLayout
        android_layout_width="match_parent"
        android_layout_height="wrap_content">
    
    <ImageView
        android_id="@+id/previous_button"
        android_layout_width="wrap_content"
        android_layout_height="wrap_content"
        android_layout_alignParentStart="true"
        android_layout_marginStart="5dp"
        android_layout_marginTop="5dp"
        android_layout_marginEnd="5dp"
        android_layout_marginBottom="5dp"
        android_src="@drawable/img1"
        tools_ignore="ContentDescription" />

    <TextView
        android_id="@+id/txt1"
        android_layout_width="wrap_content"
        android_layout_height="wrap_content"
        android_layout_centerVertical="true"
        android_text="@string/name"
        android_textAlignment="center"
        android_layout_toEndOf="@+id/previous_button"
        android_layout_toStartOf="@+id/next_button"
        android_textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
        android_textColor="@color/black" />

    <ImageView
        android_id="@+id/next_button"
        android_layout_width="wrap_content"
        android_layout_height="wrap_content"
        android_layout_alignParentEnd="true"
        android_layout_margin="5dp"
        android_src="@drawable/img2"
        tools_ignore="ContentDescription"/>
    
</RelativeLayout>

Problem :

I have a RelativeLayout that contains two ImageViews (one at the left and the other one at the right) and one TextView (at the center)

This is what I have:

                   <RelativeLayout
                        android_layout_width="match_parent"
                        android_layout_height="wrap_content">

                        <ImageView
                            android_id="@+id/previous_button"
                            android_layout_width="wrap_content"
                            android_layout_height="wrap_content"
                            android_layout_alignParentStart="true"
                            android_layout_marginStart="5dp"
                            android_layout_marginTop="5dp"
                            android_layout_marginEnd="5dp"
                            android_layout_marginBottom="5dp"
                            android_src="@drawable/img1"
                            tools_ignore="ContentDescription" />

                        <TextView
                            android_id="@+id/txt1"
                            android_layout_width="wrap_content"
                            android_layout_height="wrap_content"
                            android_layout_centerHorizontal="true"
                            android_layout_centerVertical="true"
                            android_text="@string/name"
                            android_textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
                            android_textColor="@color/black" />


                        <ImageView
                            android_id="@+id/next_button"
                            android_layout_width="wrap_content"
                            android_layout_height="wrap_content"
                            android_layout_alignParentEnd="true"
                            android_layout_margin="5dp"
                            android_src="@drawable/img2" />
                    </RelativeLayout>

I have seen the following warning in the TextView (txt1):

If relative layout has text or button items aligned to left and right
sides they can overlap each other due to localized text expansion
unless they have mutual constraints like toEndOf/toStartOf.

I have been searching for information from other posts but I have not seen it clearly how could I solve it in my case. I would appreciate all the possible help. Thanks

READ  [FIXED] java - Opengl ES glGetAttribLocation problem! 0x0502 error
Powered by Inline Related Posts
Android Tags:android, android-layout, layout, xml

Post navigation

Previous Post: [FIXED] Unable to connect Firebase in Android Emulator for Flutter Project
Next Post: [FIXED] android – Highlight only one Card in Compose through selection

Related Posts

[FIXED] android – CharArray as Field modify the request data input Android
[FIXED] java – How to send data over public IP? Android
[FIXED] Loading data to a String Array from a String holding the array data in java Android Studio Android
[FIXED] python – kivy – how to prepare app for touch events Android
[FIXED] Android – FileNotFoundException open failed: EACCES (Permission denied) Android
[FIXED] Latest Android Studio – Problem adding Google Service Gradle plugin to build.gradle file Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What is the rising action in Julius Caesar?
  • How do you secure a rope to itself?
  • Does waterproof laminate scratch easily?
  • What makes a building prewar?
  • What can you learn in a month without alcohol?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme