Android ListView GUI 困难

发布于 2025-01-08 09:45:47 字数 3297 浏览 1 评论 0原文

https://i.sstatic.net/4Irb3.png

单击上面的链接查看屏幕截图。

好的,我在编辑 xml 布局以使此列表看起来不错时遇到一些问题。基本上我希望每一行信息填充整个列表行,以便您在每行之间看到的空白不存在。我尝试过在 row.xml 和 main.xml 中操作多个不同的属性,但到目前为止没有任何效果。有人有什么建议吗?感谢

row.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:paddingTop="4dip"
     android:paddingBottom="6dip"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:textColor="@color/white" 
     android:orientation="horizontal">

     <TextView android:id="@+id/position"
         android:textColor="@color/white"
         android:background="@color/black"
         android:layout_width="20dip"
         android:textSize="14dip"
         android:gravity="center"
         android:layout_height="fill_parent"/>

     <TextView android:id="@+id/team_name"
         android:textColor="#000000"
         android:background="@color/grey"
         android:gravity="center"
         android:layout_width="70dip"
         android:textSize="14dip"
         android:layout_height="fill_parent" 
         android:layout_weight="1"/>

     <TextView android:id="@+id/games_played"
         android:textColor="#000000"
         android:background="@color/cyan"
         android:layout_width="5dip"
         android:textSize="14dip"
         android:gravity="center"
         android:layout_height="fill_parent"  
         android:layout_weight="1"/>

      <TextView android:id="@+id/points"
         android:textColor="#000000"
         android:background="@color/turquoise"
         android:layout_width="5dip"
         android:textSize="14dip"
         android:gravity="center"
         android:layout_height="fill_parent"  
         android:layout_weight="1"/>
</LinearLayout>

main.xml

<?xml version="1.0" encoding="utf-8"?>
    <TableLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@color/white"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="1">
    <TableRow>
     <TextView 
        android:text="Team"
        android:background="@color/red"
        android:textColor="@color/white" 
        android:gravity="right"
        android:layout_width="wrap_content" />
    <TextView 
        android:text="Games Played"
        android:background="@color/red"
        android:textColor="@color/white" 
        android:gravity="center"
        android:layout_width="wrap_content"
        android:paddingLeft="22dip" />

    <TextView 
        android:text="Points"
        android:background="@color/red"
        android:textColor="@color/white" 
        android:gravity="left"
        android:layout_width="wrap_content"
        android:paddingRight="18dip"/>
    </TableRow>

    <TableRow >
    <ListView
        android:background="@color/white" 
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:layout_weight="1"/>
    </TableRow>
</TableLayout>

https://i.sstatic.net/4Irb3.png

click above link for screen shot.

Ok so i'm having some problems editing my xml layout to get this list looking good. Basically i want each row of info to fill the whole list row, so that the white space you see in between each row isn't there. I have tried manipulating multiple different attributes in the row.xml and the main.xml but nothing has worked so far. Anyone have any advice? Thanks

row.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:paddingTop="4dip"
     android:paddingBottom="6dip"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:textColor="@color/white" 
     android:orientation="horizontal">

     <TextView android:id="@+id/position"
         android:textColor="@color/white"
         android:background="@color/black"
         android:layout_width="20dip"
         android:textSize="14dip"
         android:gravity="center"
         android:layout_height="fill_parent"/>

     <TextView android:id="@+id/team_name"
         android:textColor="#000000"
         android:background="@color/grey"
         android:gravity="center"
         android:layout_width="70dip"
         android:textSize="14dip"
         android:layout_height="fill_parent" 
         android:layout_weight="1"/>

     <TextView android:id="@+id/games_played"
         android:textColor="#000000"
         android:background="@color/cyan"
         android:layout_width="5dip"
         android:textSize="14dip"
         android:gravity="center"
         android:layout_height="fill_parent"  
         android:layout_weight="1"/>

      <TextView android:id="@+id/points"
         android:textColor="#000000"
         android:background="@color/turquoise"
         android:layout_width="5dip"
         android:textSize="14dip"
         android:gravity="center"
         android:layout_height="fill_parent"  
         android:layout_weight="1"/>
</LinearLayout>

main.xml

<?xml version="1.0" encoding="utf-8"?>
    <TableLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@color/white"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="1">
    <TableRow>
     <TextView 
        android:text="Team"
        android:background="@color/red"
        android:textColor="@color/white" 
        android:gravity="right"
        android:layout_width="wrap_content" />
    <TextView 
        android:text="Games Played"
        android:background="@color/red"
        android:textColor="@color/white" 
        android:gravity="center"
        android:layout_width="wrap_content"
        android:paddingLeft="22dip" />

    <TextView 
        android:text="Points"
        android:background="@color/red"
        android:textColor="@color/white" 
        android:gravity="left"
        android:layout_width="wrap_content"
        android:paddingRight="18dip"/>
    </TableRow>

    <TableRow >
    <ListView
        android:background="@color/white" 
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:layout_weight="1"/>
    </TableRow>
</TableLayout>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

逆蝶 2025-01-15 09:45:47

您是否设置了 android:minHeight 属性以及 LinearLayout 的 android:layout_height ?这将修复行高。

Did you set android:minHeight prop as well as android:layout_height of LinearLayout? this will fixes the row height.

柠檬色的秋千 2025-01-15 09:45:47

我想通了,我必须删除线性布局中的填充属性,不敢相信我之前没有弄清楚!

i figured it out, i had to remove the padding attributes in the linearlayout, can't believe i didn't figure it out before!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文