Android HorizontalScrollView 水平滑动 在listview上面动态添加图片
Android HorizontalScrollView 水平滑动 listview 上动态添加图片
最近遇到了个 在listview展示广告的需要动态添加图片
如图:
使用了 horizontalScrollView 在listview上进行添加
java代码:
package com.baozi.bzhorizontalscrollview;import java.util.ArrayList;import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;public class MainActivity extends Activity {private ListView lv;private View headerView;private LinearLayout header_ll;ArrayList<String> arrayList = new ArrayList<String>();@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);lv = (ListView) findViewById(R.id.lv);headerView = LayoutInflater.from(this).inflate(R.layout.item_home_header, null);header_ll = (LinearLayout) headerView.findViewById(R.id.header_ll);for (int i = 0; i < 10; i++) {View coupon_home_ad_item = LayoutInflater.from(this).inflate(R.layout.home_item, null);ImageView icon = (ImageView) coupon_home_ad_item.findViewById(R.id.coupon_ad_iv);// 拿个这行的icon 就可以设置图片final String href = "http://www.blog.csdn.net/aaawqqq";if (!TextUtils.isEmpty(href)) {coupon_home_ad_item.setOnClickListener(new OnClickListener() {// 每个item的点击事件加在这里@Overridepublic void onClick(View v) {Uri uri = Uri.parse(href);Intent intent = new Intent(Intent.ACTION_VIEW,uri);startActivity(intent);}});}header_ll.addView(coupon_home_ad_item);}lv.addHeaderView(headerView);// 通过listview的addHeaderView方法 将header添加到// listview里面// listview的测试数据for (int i = 0; i < 20; i++) {arrayList.add(i + " ------------- "+ System.currentTimeMillis());}ArrayAdapter adapter = new ArrayAdapter(this, R.layout.item,R.id.textView1, arrayList);lv.setAdapter(adapter);}
}
xml代码:
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:background="#f4f4f4"android:paddingBottom="@dimen/activity_vertical_margin"android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"tools:context="com.baozi.bzhorizontalscrollview.MainActivity" ><ListViewandroid:id="@+id/lv"android:layout_width="fill_parent"android:layout_height="fill_parent" ></ListView></RelativeLayout>
item_home_header.xml
<?xml version="1.0" encoding="UTF-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"xmlns:ptr="http://schemas.android.com/apk/res-auto"android:id="@+id/coupon_home_ad_hv"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical"android:scrollbars="none" ><LinearLayoutandroid:id="@+id/header_ll"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginBottom="15dp"android:background="#dddddd"android:orientation="horizontal" ></LinearLayout></HorizontalScrollView>
home_item.xml
<?xml version="1.0" encoding="UTF-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:ptr="http://schemas.android.com/apk/res-auto"android:id="@+id/coupon_home_ad_ll"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginBottom="10dp"android:layout_marginLeft="5dp"android:layout_marginRight="5dp"android:layout_marginTop="10dp"android:gravity="center"android:orientation="horizontal" ><ImageViewandroid:id="@+id/coupon_ad_iv"android:layout_width="120dp"android:layout_height="90dp"android:layout_margin="4dp"android:background="@drawable/ic_launcher"android:scaleType="centerCrop" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:text="点我"android:textColor="#000000"android:textSize="20sp" /><Viewandroid:layout_width="1dp"android:layout_height="90dp"android:background="#000000" /></FrameLayout>
步骤:
首先加载 header
headerView = LayoutInflater.from(this).inflate(R.layout.item_home_header,null);
header_ll = (LinearLayout)headerView.findViewById(R.id.header_ll);
获取header里面的 LinearLayout
将服务器获取的imageview 通过for循环 add 到header上的linearlayout
添加点击事件等
demo下载地址 : http://download.csdn.net/detail/aaawqqq/8393831
转载请注明 http://blog.csdn.net/aaawqqq/article/details/25082417
不足之处请大家指导 谢谢
Android HorizontalScrollView 水平滑动 在listview上面动态添加图片相关推荐
- android horizontalscrollview 动画,Android HorizontalScrollView左右滑动效果
本文实例为大家分享了Android HorizontalScrollView左右滑动的具体代码,供大家参考,具体内容如下 效果图 一.什么是HorizontalScrollView Horizonta ...
- Android HorizontalScrollView左右滑动
Android HorizontalScrollView左右滑动 效果图 一.什么是HorizontalScrollView HorizontalScrollView实际上是一个FrameLayout ...
- android 横向滑动 回弹,android ScrollView水平滑动回弹
在研究了View的一些属性之后做了个Scroll的水平滑动回弹. 效果图: 主要代码: import android.content.Context; import android.graphics. ...
- Android --- RecyclerView 水平滑动时,一个 item 一个 item 的滑动,禁止滑动到一半停止
使用RecyclerView水平滑动显示item,一个item占整个屏幕宽度, 所以基本写法水平滑动不会一个item一个item的显示完整,而是各自显示一部分.因此这个不是我们想要的结果.效果就是像广 ...
- Android高仿网易新闻客户端之动态添加标签
承接上一篇文章:Android高仿网易新闻客户端之首页,今天来实现动态添加标签效果. 动态标签页是一个流式布局,实现了宽度自动换行高度自动分配的功能,代码如下: FlowLayout.java pac ...
- delphi listview动态添加图片_Java 添加PDF图章(印章)——图片图章、动态图章
图章(印章)是一种在合同.票据.公文等文件中表明法律效应.部门机关权威的重要指示物,常见于各种格式的文件.文档中.对于纸质文档可以手动盖章,但对于电子文档,则需要通过特定的方法来实现.本篇文档分享通过 ...
- html动态添加图片不显示不出来,解决 viewer.js 动态更新图片导致无法预览的问题...
前台页面要求图片的查看,是在表格中点击查看才弹出图片,网上发现用Viewer插件的挺多,就选用的这款插件,但是Viewer插件会产生缩略图,这里取巧了,将缩略图统一替换成了一个带有查看两字的小图片,这 ...
- swiper动态添加图片问题
swiper (Table切换和动态加载时候出现的问题) 本文为让心灵-去旅行原创,转载请说明.. 我们在写一个简单的swiper图片轮播的时候很简单,是写死的也就那么几张图片轮播.如果这时候图片和一 ...
- vue3+echarts实现世界地图以及轨线(label使用fomatter+rich动态添加图片及背景色,以及label如何添加动态边框色)
背景 最近项目开发,需要开发一个世界地图,并且实现经纬度对应的点对点轨线动效,效果如下: 问题 如何在刚打开页面的时候就显示地点名称 label如何同时添加图片和背景色 label怎么动态修改字体颜色 ...
最新文章
- 基因测序、生物信息分析平台工作站硬件配置推荐2020
- 单电源运算放大器全波整流电路_几种二极管整流电路原理图解。
- RocketMQ高性能之底层存储设计
- Android 编译系统分析(二)
- mac 卸载编辑器卸不干净
- Pyhton学习——Day25
- linux第三方模块参数,nginx 的第三方模块ngx_http_accesskey_module 来实现下载文件的防盗链步骤(linux系统下)...
- 关于 mac m1 xcode12 编译报错 this target. for architecture arm64等问题解决方案
- c语言关键字识别程序,c语言-以关键字搜索程序
- datax 不识别字段过滤_初效空气过滤器种类
- mysql-order by分页复杂排序条件替换union-limit(使用if和case when实现复杂排序)
- 原生JS实现网页导航条特效
- 还原html默认打开方式,怎么还原打开方式,详细教您Win10系统下如何还原程序默认打开方式...
- 洛谷 P2123 皇后游戏(贪心)
- ps教程:用PS和FLASH8做眨眼教材
- 游戏软件寄售官网源码带后台
- Python教程之粒子运动轨迹动态绘图
- 理解 Linux 网络栈:Linux 网络协议栈简单总结
- 阿联酋esma认证_阿联酋发布ECAS认证计划
- bootstrapt 表格自适应_BootStrap table表格插件自适应固定表头(超好用)
热门文章
- Brenda-利用SOAP API访问Brenda及本地保存
- VNC Viewer建立多个图形界面,来远程访问同一个服务器(Ubuntu)
- 干货|一文搞定 uiautomator2 自动化测试工具使用
- 微软服务器无法删除不了,[图]Edge无法卸载 引发诸多用户强烈不满
- 基于量子计算的无收益标的资产欧式看涨期权定价和delta风险分析
- 指令能被计算机硬件理解并执行,计算机
- 光流传感器 定位精度_光流定位原理是什么??
- win10无线投屏_win10电脑投屏要无线投屏器吗?
- html雨滴状的图案代码,HTML_HTML5实现晶莹剔透的雨滴特效,复制代码代码如下: html - phpStudy...
- 通过Element开发基础增删改查页面——Vue项目实战(三)