简体   繁体   English

ListView页首横幅间距太小,我可以使行更紧密吗?

[英]ListView leaderboard is too spaced out, can I make the rows closer?

Right now I have a ListView that shows high scores in a database. 现在,我有一个ListView在数据库中显示高分。 My rows right now are very spaced out, and I'd like them to be closer. 我现在的行间隔很远,我希望它们离得更近。 However I can't figure this out. 但是我无法弄清楚。 Here's what my tables look like on the emulator: 这是我的表在模拟器上的样子:

在此处输入图片说明

Here's my code: Here is Leaderboard xml: 这是我的代码:这是排行榜xml:

<ListView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/display_listview"
    android:layout_below="@+id/time" />

Here is Leaderboard_row xml: 这是Leaderboard_row xml:

<LinearLayout

    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/mathAnswer"
    android:layout_marginTop="10dp">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@color/orange"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="-----------"
        android:textSize="25sp"
        android:textColor="#000"
        android:id="@+id/lb_rank"
        android:gravity="center"
        android:layout_alignParentLeft="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@color/orange"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="-----------"
        android:textSize="25sp"
        android:textColor="#000"
        android:id="@+id/lb_score"
        android:gravity="center"
        android:layout_toRightOf="@id/lb_rank"/>

    <TextView
        android:layout_width="130dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@color/orange"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="-----------"
        android:textColor="#000"
        android:textSize="25sp"
        android:id="@+id/lb_time"
        android:gravity="right"
        android:layout_toRightOf="@id/lb_score"/>
</LinearLayout>

Is there something I can do to make these rows closer together? 我可以做些什么使这些行靠得更近吗?

your xml looks pretty messed up. 您的xml看起来很混乱。 you are using a lot of attributes that are only for relative layout. 您正在使用许多仅用于相对布局的属性。 Try this: 尝试这个:

<LinearLayout

    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation = "horizontal"
    android:layout_marginTop="10dp">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/orange"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="-----------"
        android:textSize="25sp"
        android:textColor="#000"
        android:id="@+id/lb_rank"
        android:gravity="center" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/orange"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="-----------"
        android:textSize="25sp"
        android:textColor="#000"
        android:id="@+id/lb_score"
        android:gravity="center"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/orange"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="-----------"
        android:textColor="#000"
        android:textSize="25sp"
        android:id="@+id/lb_time"
        android:gravity="right"/>
</LinearLayout>

The line - android:layout_marginTop="10dp" in Leaderboard_row Linear Layout is adding space between rows. 该行-Leaderboard_row Linear Layout中的android:layout_marginTop =“ 10dp”在行之间添加了空间。 Removing this line should place the rows one below the other with out any space between them. 删除此行应将行排在另一行的下方,且行与行之间没有任何间距。

And android:layout_alignParentLeft, android:layout_toRightOf are Relative Layout properties and should not be used inside Linear Layout. android:layout_alignParentLeft,android:layout_toRightOf是相对布局属性,因此不应在线性布局中使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM