简体   繁体   中英

List View items too tall?

I am using a 9-patch image for my ListView as the background for each list item. With this particular 9-patch image the list items look too tall each time, like this:

在此处输入图片说明

The image looks like this:

在此处输入图片说明

Nothing in my XML code that I see indicates that the list items should be this tall. Here is my XML layout for each list item.

<?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="wrap_content"
    android:orientation="horizontal"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:background="@drawable/card">

    <LinearLayout 
        android:layout_width="40dp"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/arrowUp"
            android:src="@drawable/arrowup"
            android:layout_width="20dp"
            android:layout_height="30dp"
            android:layout_marginLeft="4dp"
            android:layout_marginTop="4dp"
            android:layout_marginRight="4dp"
            android:layout_gravity="center_horizontal"
            />

        <TextView
            android:id="@+id/scoreText"
            android:layout_width = "wrap_content"
            android:layout_height="wrap_content"
            android:text="492"
            android:textColor="#000"
            android:layout_gravity="center_horizontal"
            />

        <ImageView
            android:id="@+id/arrowDown"
            android:src="@drawable/arrowdown"
            android:layout_width="20dp"
            android:layout_height="30dp"
            android:layout_marginLeft="4dp"
            android:layout_marginTop="0dp"
            android:layout_marginRight="4dp"
            android:layout_gravity="center_horizontal"
            />

    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >

        <TextView 
            android:id="@+id/messageText"
            android:text="Message text message text message text"
            android:textSize="15sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"/>

        <TextView 
            android:id="@+id/timeText"
            android:text="14 hours ago"
            android:textSize="10sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

    </LinearLayout>



</LinearLayout>

My guess is that you don't have the proper settings for your 9-patch (the dark lines on the outside represent how the image will scale).

It is confusing to get these values correct, fortunately the ADT contains a tool to make this easier to visualize. I suggest you use this tool to fine tune the configuration of how you image scales using this tool.

http://developer.android.com/tools/help/draw9patch.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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