Skip to content

Snappy1

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

[FIXED] android – two elements in linear layout are packed to center instead of to the sides

Posted on November 11, 2022 By

Solution 1 :

Use ConstraintLayout

<android.support.constraint.ConstraintLayout 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="wrap_content">
    <com.google.android.libraries.onegoogle.account.particle.AccountParticle
        xmlns_android="http://schemas.android.com/apk/res/android"
        android_id="@+id/part_a"
        android_layout_width="wrap_content"
        android_layout_height="wrap_content"
        app_layout_constraintStart_toStartOf="parent"
        app_layout_constraintTop_toTopOf="parent"
        app_layout_constraintBottom_toBottomOf="parent"/>
    <ImageView
        android_id="@+id/part_b"
        android_layout_width="wrap_content"
        android_layout_height="wrap_content"
        android_layout_marginEnd="14dp"
        android_layout_marginRight="14dp"
        app_layout_constraintTop_toTopOf="parent"
        app_layout_constraintBottom_toBottomOf="parent"
        app_layout_constraintEnd_toEndOf="parent"
        app_srcCompat="@drawable/my_image" />
</android.support.constraint.ConstraintLayout>

Problem :

I have this layout:

<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="wrap_content"
    android_orientation="horizontal">
  <com.google.android.libraries.onegoogle.account.particle.AccountParticle
      xmlns_android="http://schemas.android.com/apk/res/android"
      android_id="@+id/part_a"
      android_layout_width="wrap_content"
      android_layout_height="wrap_content"
      android_layout_gravity="center_vertical|start" />
  <ImageView
      android_id="@+id/part_b"
      android_layout_width="wrap_content"
      android_layout_height="wrap_content"
      android_layout_marginEnd="14dp"
      android_layout_marginRight="14dp"
      android_layout_gravity="center_vertical|end"
      app_srcCompat="@drawable/my_image" />
</LinearLayout>

I would expect part_a to be aligned to the right and part_b aligned to the left. (Thanks to android:layout_gravity).

Why do I see them packed closed to each other?

enter image description here

Comments

Comment posted by MichaelStoddart

Post some code..

Comment posted by Elad Benda

@MichaelStoddart my bad, the xml wasn’t seen

READ  [FIXED] java - How to Execute an activity N times ,Where N is user input
Powered by Inline Related Posts
Android Tags:android, android-layout, android-linearlayout, layout-gravity

Post navigation

Previous Post: [FIXED] android – Convert BMP image to PNG or JPG in Java without loading the entire image in memory
Next Post: [FIXED] xml – Android – prevent TextView to push out another element inside LinearLayout

Related Posts

[FIXED] android – Getting the following error while importing data from Firebase:The method ‘[]’ was called on null Android
[FIXED] java – My application is implementing a Google map capabiity. I amd getting a location permission error on Android
[FIXED] android – NavController.OnDestinationChangedListener passes a destination.id not matching the triggered Navigation Action ID Android
[FIXED] android – Type inference failed: Not enough information to infer parameter T in fun getApplicationContext(): T! Please specify it explicitly Android
[FIXED] android – RxJava blockingFirst/Single returns wrong exception in JUnit 5 Retrofit Test Android
[FIXED] Implementing the Huawei IAP on Android 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