代码之家  ›  专栏  ›  技术社区  ›  endryha

在Android中如何在两个图像之间放置文本

  •  0
  • endryha  · 技术社区  · 15 年前

    我想创建布局,我有两个图像在左,在右,文本在中心。

    我试着用相对的布局来做,但不幸的是没有成功。有谁能给我举个例子吗?

    1 回复  |  直到 15 年前
        1
  •  5
  •   Cristian    15 年前

    你试过类似的东西吗?

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <ImageView
            android:id="@+id/img1"
            android:layout_width="50dip"
            android:layout_height="50dip"
            android:layout_alignParentLeft="true"
            android:src="@drawable/image1"/>
        <ImageView
            android:id="@+id/img2"
            android:layout_width="50dip"
            android:layout_height="50dip"
            android:layout_alignParentRight="true"
            android:src="@drawable/image2"/>
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/img1"
            android:layout_toLeftOf="@id/img2"
            android:layout_alignTop="@id/img1"
            android:text="I'm between!"/>
    </RelativeLayout>
    

    如果你不需要更多的东西,你可以使用 LinearLayout 相反,因为它更容易实现。在这种情况下,你只需要玩 layout_weight 属性。

    alt text