开发者

How to place a text between two images in Android

I want to create layout where I have two images at left and at right and text in center.

I have tried to do it with relative layout but unfortun开发者_运维问答etly it was unsuccessfully. Could anybody provide me an example?


Have you tried something like?

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

If you don't need more things on your view, you could want to use LinearLayout instead, since it's more easier to implement. In that case, you just have to play with the layout_weight attribute.

How to place a text between two images in Android

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜