android的List View的Item布局问题
伊谢尔伦
伊谢尔伦 2017-04-18 09:13:15
[Android讨论组]

我希望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>
伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

全部回复(2)
PHP中文网

线性布局,你的第一个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就最好不要用,滥用会有性能问题。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号