代码之家  ›  专栏  ›  技术社区  ›  Deepak Rana

两个视图之间的左、右和中心间距相等Android

  •  -1
  • Deepak Rana  · 技术社区  · 6 年前

    嘿,伙计们,请帮帮我。我想要两个文本视图之间从左、右和中间等距的空间。下面是我想要的视图的图像。 enter image description here

    两个文本视图的宽度可以根据文本在运行时增减。

    3 回复  |  直到 6 年前
        1
  •  1
  •   Radesh    6 年前

    用这个

    <?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>
    
        2
  •  0
  •   Mirza Ahmed Baig    6 年前

    使用中心水平约束的约束布局

    <?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>
    
        3
  •  -1
  •   bilal    6 年前

    使用重心重量。

    <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>