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

end*_*yha 0 java android

我想创建布局,其中左侧和右侧有两个图像,中间有文本.

我试图用相对布局做到这一点,但不幸的是它没有成功.有人可以举个例子吗?

Cri*_*ian 5

你尝试过类似的东西吗?

<?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>
Run Code Online (Sandbox Code Playgroud)

如果您在视图中不需要更多内容,则可能需要使用LinearLayout,因为它更容易实现.在这种情况下,您只需要使用该layout_weight属性.

替代文字