在listview android中设置图像之间的文本

在listview android中设置图像之间的文本,android,Android,嗨,我有一些项目的列表,每个列表在左角有一个图像,文本显示在其右侧,我想在listview中显示图像之间的文本,所以如何做我的xml是 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height

嗨,我有一些项目的列表,每个列表在左角有一个图像,文本显示在其右侧,我想在listview中显示图像之间的文本,所以如何做我的xml是

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="horizontal"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
 >
  <ImageView
    android:id="@+id/img"
    android:scaleType="centerCrop"
    android:layout_width="70dp"
    android:layout_height="70dp"/>
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:orientation="vertical"
       android:paddingLeft="10dp"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
   >
    <TextView
    android:layout_width="fill_parent"
    android:layout_centerVertical="true"
    android:id="@+id/title"
    android:layout_height="wrap_content"
    android:textStyle="bold"
    android:textColor="#ffffff"
    android:textSize="16sp" />

    </LinearLayout>
    </LinearLayout>

是否要创建一个左侧有图像,旁边有文本的列表?如果这是您必须实现自己的阵列适配器的要点。然后,您可以为列表的每一行设置图像和文本。
也许这个链接会帮助你:

你可以像这样使用soemtihng

<TextView
    android:layout_width="fill_parent"
    android:layout_centerVertical="true"
    android:id="@+id/title"
    android:layout_height="wrap_content"
    android:textStyle="bold"
    android:textColor="#ffffff"
    android:textSize="16sp" 
    android:drawableLeft="R.drawble.img"
    android:drawableRight="R.drawble.img2"
/>

我用以下内容创建了一个新视图:

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

        android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:src="@drawable/icon"/>
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" 
        android:gravity="center_horizontal"/>
</LinearLayout>


在预览中,它将文本视图的文本居中于图片和边框之间。所以这应该行得通。如何将新元素添加到列表中?是否在控制器中使用自定义的阵列适配器来处理元素的添加?

是否要将图像设置为项目的背景?如屏幕快照url中显示的第一幅图像androidpeople.com/tag/gravity image,然后是文本,但图像中间显示的第一幅图像如屏幕快照url图像中显示的第一幅图像,然后是文本,但图像中间显示的第一幅图像屏幕截图url androidpeople.com/tag/gravity image然后是文本但图像的中间您想将文本放置在图像上还是想将文本居中放置在图像和右边框之间的剩余空间?页面上的第一项显示旁边有文本的图像。要将文本居中放置在图像和右边框之间的剩余空间中吗bordeDid您可以尝试:android:layout\u centerHorizontal=“true”或android:gravity=“center\u horizontal”?android:layout\u centerHorizontal=“true”它使屏幕的文本居中,但我希望列表视图中的图像居中