listview aligend右侧的两个textviews

时间:2014-10-24 00:33:07

标签: android

我想在我的列表视图上看到2个文本视图,我希望其中一个有正确对齐和另一个对齐中心,但所有这些都是aligend left !!!我的listview xml:

  <?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:background="#ffffff"
  android:orientation="vertical">

  <TextView 
    android:layout_gravity="center"
    android:gravity="center"
    android:id="@+id/tv_subject"
    android:layout_weight="0.5"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"     
    android:textSize="13sp"   
    android:textStyle="bold" />

  <LinearLayout 
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="horizontal">    

  <ImageView 
    android:id="@+id/iv_pic"
    android:layout_gravity="left"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="5dp"
    android:contentDescription="ads"/>

   <TextView 
    android:layout_gravity="right"
    android:gravity="right"
    android:textColor="#ffffff"
    android:paddingRight="5dp"
    android:layout_weight="0.5"
    android:id="@+id/tv_details"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>
    </LinearLayout>
  </LinearLayout>

这段代码工作成功,但是当编译器构建应用程序时我想在列表视图中触摸一行,实际上当我的手指在列表视图时,行的颜色应该改变,但是因为我必须设置宽度match_parent它覆盖了整个屏幕。 如何将此输出设置为我想要的输出,当我的手指在所选行上时,用户会看到该行的颜色已更改。

1 个答案:

答案 0 :(得分:0)

只需删除android:background="#ffffff"即可。如果要更改颜色 - 将其设置为ListView。