listView里面嵌套自定义的图片,文字,按钮
2014-11-13 21:48
357 查看
不多说,先上图:
这里就只写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>
核心代码已经给大家展示出来了。。其他的就不方便显示了。。
这里就只写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>
核心代码已经给大家展示出来了。。其他的就不方便显示了。。
相关文章推荐
- Android中的ListView实现图片文字和按钮
- 自定义导航栏按钮UIBarButtonItem 文字或图片
- iOS心得7 按钮的图片和文字自定义位置
- Swift里自定义一个文字在左、图片在右的,标题按钮
- 自定义按钮 文字在左图片在右
- 实现、文件-Android中的ListView实现图片文字和按钮-by小雨
- 新浪微博开发八(自定义标题按钮,解决图片在文字右边的问题)
- JQuery 可自定义自动播放图片 文字 也可以带按钮点击特效
- TableView里面的cell根据图片或者文字自定义高度
- IOS学习 NSNavigationController 自定义:左右按钮、中间文字、背景图片
- Android ListView常用用法 (实现文字图片和按钮)
- ListView 中显示自定义单选列表,实现单选效果(左文字,右图片)
- 自定义属性之LinearLayout ImageView TextView模拟图片文字按钮
- NavigationItem按钮的自定义(图片+文字)
- android实现自定义图片+文字按钮
- 自定义导航栏按钮UIBarButtonItem 文字或图片
- 自定义Dialog(图片,文字说明,单选按钮)----类ListPreference实现(2)
- 自定义Dialog(图片,文字说明,单选按钮)----类ListPreference实现(2)
- JQuery左右按钮控制图片 文字向上滚动自定义插件
- 自定义导航栏按钮UIBarButtonItem 文字或图片