-2

文本视图应填充图像留下的空间:

[imageview 40px, aligned left][textview][imageview 40px, aligned right]

这是我的代码:

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

    <ImageView
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:src="@drawable/indicator_code_lock_point_area_green_holo"
        android:tag="heart" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingBottom="8dp"
        android:paddingTop="8dp"
        android:text="Shakespeare was a respected poet and playwright in his own day, but his reputation did not rise to its present heights until the 19th century." />

    <ImageView
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:src="@drawable/indicator_code_lock_point_area_green_holo"
        android:tag="heart" />

</LinearLayout>

如您所见,文本占据了右侧的图像。

4

4 回答 4

0

在 XML 中为文本视图写这个

<TextView
        android:id="@+id/TextView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:drawableLeft="@android:drawable/ic_menu_call"
        android:drawableRight="@android:drawable/ic_menu_call"
        android:gravity="center_horizontal|center_vertical"
        android:minHeight="100dp"
        android:padding="20dp"
        android:text="Contacts"/>

这里,

android:drawableLeft="@android:drawable/ic_menu_call"
android:drawableRight="@android:drawable/ic_menu_call"

设置图像

于 2013-05-08T17:19:38.203 回答
0

你可以尝试这样的事情:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
            android:layout_weight="1"
            android:gravity="center_horizontal"
            android:text="Your Text Goes Here" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:layout_weight="1"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>

</LinearLayout>
于 2013-05-13T18:18:05.863 回答
0

如果你使用LinearLayout你只需要设置weight=1width=0dp为你的TextView

<TextView
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:paddingBottom="8dp"
        android:paddingTop="8dp"
        android:text="Shakespeare was a respected poet and playwright in his own day, but his reputation did not rise to its present heights until the 19th century." />

但是,如果您没有为ImageViews 设置 id 并且如果您的可绘制ImageView对象不是 9.png Anupam Majhi的答案更好(您不需要以这种方式使用 ImageView)。

于 2013-05-08T17:42:00.897 回答
0

使用drawableLeftdrawableRight属性。

于 2013-05-08T17:16:36.170 回答