android的List View的Item布局问题

我希望listView的item横向显示三块内容,分别位于listitem的左,中,右位置;中间的有两个TextView,竖直排列;下面是代码,调试了一天也没弄出来,麻烦大家帮忙看看,谢谢

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

    <TextView
        android:id="@+id/word"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_vertical"
        android:text="aaaaaaaaa" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_horizontal"
        android:orientation="vertical">

        <TextView
            android:id="@+id/_en"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="**********" />

        <TextView
            android:id="@+id/_am"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="+++++++++" />
    </LinearLayout>

    <TextView
        android:id="@+id/meaning"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center_vertical"
        android:layout_gravity="right"
        android:text="ddddddddddd" />

</LinearLayout>
阅读 4k
2 个回答

线性布局,你的第一个textview已经设成占满整个空间了,你的中、右布局当然出不来了,姑且认为你左中右三块平均分配水平空间,可以这么写

<?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="horizontal"
    android:gravity="center_vertical">

    <TextView
        android:id="@+id/word"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center_vertical"
        android:text="aaaaaaaaa" />

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center_horizontal"
        android:orientation="vertical">

        <TextView
            android:id="@+id/_en"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="**********" />

        <TextView
            android:id="@+id/_am"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="+++++++++" />
    </LinearLayout>

    <TextView
        android:id="@+id/meaning"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center_vertical"
        android:text="ddddddddddd" />

</LinearLayout>

剩下的文字排列你再细调了。

用linearLayout的weight就好了,item根布局是一个横向linearLayout,子布局weight都是1,第二个子布局是一个纵向的linearLayout,然后它的子布局是两个weight为1的textView。
不过能不用weight就最好不要用,滥用会有性能问题。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题