ListView排行榜太多了,我可以让行更接近吗?

时间:2016-05-12 18:04:53

标签: java android xml

现在我有一个在数据库中显示高分的ListView。我现在的排是非常分开的,我希望它们更接近。但是我无法弄清楚这一点。这是我的表在模拟器上的样子:

enter image description here

这是我的代码: 这是Leaderboard xml:

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

这是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>

我能做些什么来使这些行更接近?

2 个答案:

答案 0 :(得分:0)

你的xml看起来很混乱。您正在使用许多仅用于相对布局的属性。试试这个:

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

答案 1 :(得分:0)

Leaderboard_row线性布局中的行 - android:layout_marginTop =&#34; 10dp&#34; 在行之间添加空格。删除此行应将行放在另一行之下,并在它们之间留出任何空格。

android:layout_alignParentLeft,android:layout_toRightOf是相对布局属性,不应在线性布局中使用。