从ListView的顶部显示记录

问题描述:

我正在写一个应用程序,其中我正在抓取Facebook朋友的列表,这些生日在未来30天,我也能够获取。从ListView的顶部显示记录

但我面临的非常小的问题

我看到了,如果我在一个列表有超过4条,然后我从上面获取的朋友列表,如果我有1个或2中的记录然后列出我在底部得到结果,就像下面的屏幕截图:

请告诉我,我怎么能解决这个问题,IW * 蚂蚁上显示不是底部顶部这些记录... *

activityfb_friends.xml:

<?xml version="1.0" encoding="utf-8"?> 

<ListView 
    android:id="@+id/friends_list" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:cacheColorHint="#00000000" 
    android:divider="#b5b5b5" 
    android:layout_above="@+id/greeting" 
    android:dividerHeight="1dp" /> 

<ImageButton 
    android:id="@+id/greeting" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    android:background="@drawable/greet" 
    android:layout_marginTop="10dp" 
    android:layout_marginBottom="10dp" /> 

</RelativeLayout> 

listfb_friends.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_marginBottom="5dp" 
android:layout_marginLeft="10dp" 
android:layout_marginRight="10dp" 
android:layout_marginTop="5dp" 
android:background="@drawable/btn_background" 
android:gravity="center" 
android:orientation="horizontal" 
android:padding="5dip" > 

<RelativeLayout 
    android:id="@+id/friend_item" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_marginRight="5dip" 
    android:background="@drawable/image_background" 
    android:padding="3dip" > 

    <ImageView 
     android:id="@+id/picture" 
     android:layout_width="50dip" 
     android:layout_height="50dip" 
     android:src="@drawable/img"/> 
</RelativeLayout> 

<TextView 
    android:id="@+id/name" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignTop="@+id/friend_item" 
    android:layout_toRightOf="@+id/friend_item" 
    android:textColor="#324e87" 
    android:textSize="15dip" 
    android:textStyle="bold" 
    android:typeface="sans" /> 

<TextView 
    android:id="@+id/dob" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/name" 
    android:layout_marginTop="1dip" 
    android:layout_toRightOf="@+id/friend_item" 
    android:textColor="#343434" 
    android:textSize="15dip" 
    /> 

</RelativeLayout> 

的问题是@+id/friends_list布局。您已将其设置为layout_height="wrap_content",并设置为layout_above="@+id/greeting"。这意味着它只会适合包含物品的大小,并且它会出现在问候按钮(您已经锚定到容器底部)的正上方。

最简单的解决方法是删除layout_above并用android:layout_alignParentTop="true"替换它。这将把列表锚定到容器的顶部,而不是在问候图像按钮上方。

尝试在列表视图中添加android:layout_alignParentTop="true"谁是id是friends_list