listView里面嵌套自定义的图片,文字,按钮

不多说,先上图:



这里就只写listView部分了。。。。

adapter...


public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if (position == 0) {
return getView();
} else {
ViewHolder holder = null;
if (convertView == null) {
holder = new ViewHolder();
convertView = View.inflate(activity,
R.layout.recom_musiclist_item_new, null);
holder.nameTv = (TextView) convertView
.findViewById(R.id.musicname_tv);
holder.numTv = (TextView) convertView
.findViewById(R.id.artist_tv);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
if (holder == null) {
holder = new ViewHolder();
convertView = View.inflate(activity,
R.layout.recom_musiclist_item_new, null);
holder.nameTv = (TextView) convertView
.findViewById(R.id.musicname_tv);
holder.numTv = (TextView) convertView
.findViewById(R.id.artist_tv);


convertView.setTag(holder);
}
}
Tbl_audio audio = list.get(position - 1);
holder.nameTv.setText((position) + "." + audio.getAudio_title());
holder.numTv.setText(audio.getAudio_singer_name());
// 给按钮绑定点击事件
ImageButton addtoList = (ImageButton) convertView
.findViewById(R.id.addToList);
ImageButton download = (ImageButton) convertView
.findViewById(R.id.download);
addtoList.setOnClickListener(new Clicks(audio));
return convertView;
}
}


private class ViewHolder {
TextView nameTv, numTv;
}


public View getView() {
View view = View.inflate(activity, R.layout.recom_img_info, null);
AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
LayoutParams.FILL_PARENT, 600);
System.out.println(channel.getAtchannel_info());
ImageView img = (ImageView) view.findViewById(R.id.music_recom_img);
Bitmap bitmap = getLoacalBitmap(channel.getAtchannel_image());
if (bitmap != null) {
img.setImageBitmap(bitmap);
}
TextView info = (TextView) view.findViewById(R.id.music_recom_info);
info.setText(channel.getAtchannel_info());
view.setLayoutParams(lp);
view.setPadding(10, 10, 10, 20);
return view;
}

............顺便给出这两个xml文件

recom_img_info.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >


    <ImageView
        android:id="@+id/music_recom_img"
        android:layout_width="fill_parent"
        android:layout_height="200.0dip"
        android:background="#333333"
        android:scaleType="fitXY" />


    <TextView
        android:id="@+id/music_recom_info"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/music_recom_img"
        android:layout_marginTop="10.0dip"
        android:textSize="15.0sp" />


    <Button
        android:id="@+id/download_list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@id/music_recom_info"
        android:text="下载" />


    <Button
        android:id="@+id/add_all_toList"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/music_recom_info"
        android:layout_toLeftOf="@id/download_list"
        android:text="添加到.." />


    <Button
        android:id="@+id/select_all"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/music_recom_info"
        android:layout_toLeftOf="@id/add_all_toList"
        android:text="全选" />


</RelativeLayout>



主xml文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/music_recom_content"
    android:layout_width="match_parent"
    android:background="#87ceeb"
    android:layout_height="match_parent" >


    <RelativeLayout
        android:id="@+id/music_content_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >


        <ImageButton
            android:id="@+id/backBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:background="@drawable/selector_music_btn"
            android:padding="10dip"
            android:src="@drawable/icon_back" />


        <TextView
            android:id="@+id/music_recom_text"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:gravity="center"
            android:text="推荐"
            android:textSize="25.0sp" />
    </RelativeLayout>


    <ListView
        android:id="@+id/music_recom_list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginTop="20.0dip"       
         android:layout_below="@id/music_content_title" >
    </ListView>
</RelativeLayout>


核心代码已经给大家展示出来了。。其他的就不方便显示了。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值