Skip to content

Snappy1

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

[FIXED] xml – Android – prevent TextView to push out another element inside LinearLayout

Posted on November 11, 2022 By

Solution 1 :

You just need to add this line to the TextView android:layout_weight="1"

this is the final XML

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


    <TextView
        android_id="@+id/profileNickname"
        android_layout_width="wrap_content"
        android_layout_height="wrap_content"
        android_layout_weight="1"
        android_gravity="center"
        android_scrollHorizontally="false"
        android_text="No Nickname yet fdg d trdt rdrt tdr  td trd t"
        android_textColor="#FFF"
        android_textSize="24sp"
        app_layout_constraintBottom_toBottomOf="parent"
        app_layout_constraintEnd_toEndOf="parent"
        app_layout_constraintStart_toEndOf="parent"
        app_layout_constraintTop_toTopOf="parent" />

    <ImageView
        android_id="@+id/btnEditNickname"
        android_layout_width="42dp"
        android_layout_height="42dp"
        android_layout_marginLeft="8dp"
        android_layout_gravity="center"
        android_padding="6dp"
        android_scaleType="fitXY"
        app_srcCompat="@android:drawable/ic_menu_edit" />
</LinearLayout>

Solution 2 :

Try this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns_android="http://schemas.android.com/apk/res/android"
    xmlns_app="http://schemas.android.com/apk/res-auto"
    android_layout_width="match_parent"
    android_layout_height="match_parent"
    android_gravity="center"
    android_orientation="horizontal">

    <LinearLayout
        android_layout_width="0dp"
        android_layout_height="wrap_content"
        android_layout_weight="1">

        <TextView
            android_id="@+id/profileNickname"
            android_layout_width="wrap_content"
            android_layout_height="wrap_content"
            android_gravity="center"
            android_scrollHorizontally="false"
            android_text="No Nickname yet fdg d trdt rdrt tdr  td trd t"
            android_textColor="#FFFFFF"
            android_textSize="24sp" />
    </LinearLayout>

    <LinearLayout
        android_layout_width="wrap_content"
        android_layout_height="wrap_content">

        <ImageView
            android_id="@+id/btnEditNickname"
            android_layout_width="42dp"
            android_layout_height="42dp"
            android_layout_marginLeft="8dp"
            android_padding="6dp"
            android_scaleType="fitXY"
            app_srcCompat="@android:drawable/ic_menu_edit" />
    </LinearLayout>
</LinearLayout>

It’ll give you the following result:

enter image description here

And don’t forget to change the text color of the textView to that you want.

Problem :

This is the Layout:

    <LinearLayout
        android_layout_width="0dp"
        android_layout_height="wrap_content"
        android_gravity="center"
        android_orientation="horizontal"
        app_layout_constraintEnd_toEndOf="parent"
        app_layout_constraintStart_toStartOf="parent"
        app_layout_constraintTop_toBottomOf="@id/profileUserImage">

        <TextView
            android_id="@+id/profileNickname"
            android_layout_width="wrap_content"
            android_layout_height="wrap_content"
            android_gravity="center"
            android_scrollHorizontally="false"
            android_text="No Nickname yet fdg d trdt rdrt tdr  td trd t"
            android_textColor="@color/colorText"
            android_textSize="24sp"
            app_layout_constraintBottom_toBottomOf="parent"
            app_layout_constraintEnd_toEndOf="parent"
            app_layout_constraintStart_toEndOf="parent"
            app_layout_constraintTop_toTopOf="parent" />

        <ImageView
            android_id="@+id/btnEditNickname"
            android_layout_width="42dp"
            android_layout_height="42dp"
            android_layout_marginLeft="8dp"
            android_padding="6dp"
            android_scaleType="fitXY"
            app_srcCompat="@android:drawable/ic_menu_edit" />

    </androidx.appcompat.widget.LinearLayoutCompat>

When profileNickname is getting too long, it pushes out btnEditNickname out of the LinearLayout and also overlays itself out of the Layout a bit before the text is getting wrapped. How can I get this annoying piece of c*** to wrap IN TIME, before ruining everything?? I’m getting sick of wasting hours of time for minor bs like that, I hate android!

READ  [FIXED] How to apply filters by name and price on list fetched from firebase android
Powered by Inline Related Posts
Android Tags:android, android-layout, xml

Post navigation

Previous Post: [FIXED] activity_main.xml for android studio stuck on loading
Next Post: Can a beginner learn Moonlight Sonata 1st Movement?

Related Posts

[FIXED] java – android.database.sqlite.SQLiteException: no such column: bucket_display_name Android
[FIXED] java – how do I set an Error message on spinner and button like on edittext without using toast message? Android
[FIXED] java – To send whatsapp message automatically Android
[FIXED] java – I have Implement Bluetooth to my app and when i click on Bluetooth on or Off the side closs and it comes a error Message Android
[FIXED] android – How to give the GoogleMap API inside a fragment a specific map seach Android
[FIXED] android – RecyclerView in a Fragment not loading 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 a good substitute for condensed milk?
  • ¿Como el cuerpo te avisa cuando te va a dar un infarto?
  • What is the luxury brand of Jaguar?
  • Who is Big poppa baseball player?
  • What material are foam runners?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme