android开发教程之使用listview显示qq联系人列表

2019-12-10 20:10:06于海丽

    android:layout_height="wrap_content"
    android:background="#efefef" >    
    <!-- LinerLayout有比较奇怪的性质:当布局中的控件可以超出布局规定的大小 ,所以这里一行的行宽改成由内部的几个控件
    控制,而LinerLayout的layout_height改成wrap_content ..  -->
    <ImageButton 
        android:id="@+id/ct_photo"
        android:layout_height="70dip"
        android:layout_width="70dip"
        android:layout_margin="5dip"
        android:background="@drawable/contact_0"/>
    <TextView 
        android:id="@+id/ct_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dip"
        android:layout_toRightOf="@id/ct_photo"
        android:layout_alignTop="@id/ct_photo"
        android:text="为你我受冷风吹"
        android:textSize="8pt"
        android:textStyle="bold"
        android:maxLength="7"/>   
    <TextView 
        android:id="@+id/ct_sign"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dip"
        android:layout_toRightOf="@id/ct_photo"
        android:layout_alignBottom="@id/ct_photo"
        android:text="为什么受伤的总是我"
        android:textColor="#888888"/>
    <!-- 注意不是layout_padding -->
</RelativeLayout>

 

因为这里使用的是自己定义的MyAdapter类,可以更灵活的实现列表的一些功能,比如和数据库相联系,动态更新数据、添加按钮控件等等,在本例中模仿QQ列表为头像设置成了ImageButton,后面的附图中的一个Toast信息就是点击图像做出的相应,当然点击一行也可以做出相应,这个后续可能会对QQ程序做一些扩展,如增加网络模块,聊天窗口等等。到时候再进一步讨论。