Android 行中有3个元素,最后一个元素向右对齐

Android 行中有3个元素,最后一个元素向右对齐,android,Android,我如何做到这一点: <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_co

我如何做到这一点:

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

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

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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hi" />
</LinearLayout>
我使用
match\u parent
作为
Title
,但它会从屏幕上删除第二个图像。

试试这个

  <RelativeLayout
        android:id="@+id/rlMain"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:paddingBottom="20dp"
        android:paddingEnd="20dp"
        android:paddingLeft="20dp"
        android:paddingRight="10dp"
        android:paddingStart="20dp"
        android:paddingTop="20dp" >

        <ImageButton
            android:id="@+id/imgButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerHorizontal="true"
            android:layout_centerInParent="true"
            android:layout_marginRight="2dp"
            android:background="@drawable/icon_name" />

        <ImageView
            android:id="@+id/imgBook"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:scaleType="fitXY" />

        <TextView
            android:id="@+id/txtBookName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_toRightOf="@+id/imgBook"
            android:singleLine="true"
            android:text="Book Name"
            android:textColor="#000000"
            android:textSize="20sp" />
    </RelativeLayout>
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

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

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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hi" />
</LinearLayout>

用户
重量
用于此类型的布局。 或者您可以使用
RelativeLayout

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

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

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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hi" />
</LinearLayout>

更好的方法是在水平(默认)方向的线性布局中使用
android:layout\u weight

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

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

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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hi" />
</LinearLayout>
比如:

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

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

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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hi" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="3" >

<-- use your own designed backgrounds-->
<EditText
    android:id="@+id/et1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1.5"/>

 <-- use your own designed backgrounds-->
<EditText
    android:id="@+id/et2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:text="Something" />

<-- use your own designed backgrounds-->
<EditText
    android:id="@+id/et3"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1.5"/>

</LinearLayout>


您可以根据要求的设计调整权重总和和权重。

您可以显示您为此使用的布局吗请发布您迄今为止尝试的内容使用相对布局。有了它,你就可以实现这个观点。您可以将视图调整到其他视图的左侧或右侧请不要从任何位置复制粘贴任何不相关的代码。仅包括解决OPs问题所需的内容
0dp
width text用户看不到没有任何权重的视图
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

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

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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hi" />
</LinearLayout>