android - 很难将 child 与另一个 child 之间的最左和最右对齐

标签 android xml android-linearlayout

我想要左右显示两个图像,并在它们之间显示一个 TextView ,距离左侧图像只有一小段距离,但我无法完成。

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:orientation="horizontal">

     <ImageView
            android:id="@+id/image_of_services"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:src="@drawable/ic_menu_camera" />

        <TextView
            android:id="@+id/name_of_services"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:text="adasdsad"
    android:layout_weight="8"
            android:textSize="20sp" />

        <ImageView
            android:id="@+id/image_arrow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:layout_weight="2"
            android:src="@drawable/ic_menu_camera" />
    </LinearLayout>

最佳答案

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

    <ImageView
        android:id="@+id/image_of_services"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"

        android:layout_weight="2"
        android:src="@drawable/ic_menu_camera" />

    <TextView
        android:id="@+id/name_of_services"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="adasdsad"
        android:layout_weight="6"
        android:textSize="20sp" />

    <ImageView
        android:id="@+id/image_arrow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:layout_weight="2"
        android:src="@drawable/ic_menu_camera" />
</LinearLayout>`

关于android - 很难将 child 与另一个 child 之间的最左和最右对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43030069/

相关文章:

android - 用于具有多个子项目的项目列表的自定义适配器?

android - 使用 WRAP_CONTENT LayoutParams 使 TextView 文本适合一行

android - 绘制-xxxx : Eclipse Versus AVD

javascript - XPath:选择包含规范化文本的节点,不包括祖先节点

xml - XSLT 根据子元素属性对父元素进行排序

android - eclipse 中缺少 android 文件

java - 使用自定义类对象填充线性布局

android - 使用 fileOpener Ionic2 打开 app 文件夹中的文件

android - 从 IntentService 或 AsyncTask 调用 REST API?

android - 使用地理编码器和 android Google Maps API v2 获取纬度和经度