-1

Hey Guys Please help me out . I want equal space from left , right and center between two text view.Below is the image of the view which i want.enter image description here

The both text view width may be increase and decrease at run time according to text.

Deepak Rana
  • 539
  • 4
  • 18
  • 2
    Possible duplicate of [Evenly spacing views using ConstraintLayout](https://stackoverflow.com/questions/37518745/evenly-spacing-views-using-constraintlayout) – Mr. Roshan Dec 01 '18 at 11:39
  • @Mr.Roshan this is not duplicate that is for button and button width will remain constant. But in my case text view width can increase and decrease at run time – Deepak Rana Dec 01 '18 at 11:49
  • Off-topic, but did you notice the capitalized "DO NOT USE THIS TAG!" in the description of the tag [tag:space]? – Jongware Dec 05 '18 at 13:15

3 Answers3

1

Use this

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:orientation="horizontal"
    xmlns:android="http://schemas.android.com/apk/res/android">

<View
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"/>

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

<View
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"/>

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>


</LinearLayout>
Radesh
  • 13,084
  • 4
  • 51
  • 64
0

Use constraint layout with center horizontally constrain

<?xml version="1.0" encoding="utf-8"?>
<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="match_parent">


    <Button
        android:id="@+id/button"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginBottom="8dp"
        android:text="save"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/button2"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        android:text="exit"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/button" />
</android.support.constraint.ConstraintLayout>
Mirza Ahmed Baig
  • 5,605
  • 3
  • 22
  • 39
-1

Use weight with center gravity.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
    android:layout_weight="1"
    android:layout_width="0dp"
    android:text="some text1"
    android:gravity="center"
    android:layout_height="wrap_content" />
<TextView
    android:layout_weight="1"
    android:layout_width="0dp"
    android:text="some text2"
    android:gravity="center"
    android:layout_height="wrap_content" />
</LinearLayout>
bilal
  • 2,187
  • 3
  • 22
  • 23
  • that will not provide equal spacing . Suppose first text view have text "Login" and other text view have text "Sign up with email". And now check the space , it will not equal from right , left and center – Deepak Rana Dec 01 '18 at 11:45