Android HorizontalScrollView 水平滑动 在listview上面动态添加图片

本文介绍了如何在Android应用中使用HorizontalScrollView作为ListView的头部,并动态添加图片。通过LayoutInflater加载布局,创建LinearLayout,然后在点击事件中打开链接。ListView填充测试数据,实现了水平滑动查看图片的效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

@Override

public 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代码:

《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》

【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整资料开源分享

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” >

<ListView

android:id="@+id/lv"

android:layout_width=“fill_parent”

android:layout_height=“fill_parent” >

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” >

<LinearLayout

android:id="@+id/header_ll"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginBottom=“15dp”

android:background="#dddddd"

android:orientation=“horizontal” >

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” >

<ImageView

android: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” />

<TextView

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_gravity=“center”

android:text=“点我”

android:textColor="#000000"

android:textSize=“20sp” />

<View

android:layout_width=“1dp”

android:layout_height=“90dp”

android:background="#000000" />

步骤:

首先加载 header

headerView = LayoutInflater.from(this).inflate(R.layout.item_home_header,null);

header_ll = (LinearLayout)headerView.findViewById(R.id.header_ll);

最后

上面这些公司都是时下最受欢迎的互联网大厂,他们的职级、薪资、福利也都讲的差不多了,相信大家都是有梦想和野心的人,心里多少应该都有些想法。

也相信很多人也都在为即将到来的金九银十做准备,也有不少人的目标都是这些公司。

我这边有不少朋友都在这些厂工作,其中也有很多人担任过面试官,上面的资料也差不多都是从朋友那边打探来的。除了上面的信息,我这边还有这些大厂近年来的面试真题及解析,以及一些朋友出于兴趣和热爱一起整理的Android时下热门知识点的学习资料

部分文件:


准备,也有不少人的目标都是这些公司。

我这边有不少朋友都在这些厂工作,其中也有很多人担任过面试官,上面的资料也差不多都是从朋友那边打探来的。除了上面的信息,我这边还有这些大厂近年来的面试真题及解析,以及一些朋友出于兴趣和热爱一起整理的Android时下热门知识点的学习资料

部分文件:
[外链图片转存中…(img-zXdCD4Wa-1640918281705)]
[外链图片转存中…(img-wsapMhSi-1640918281706)]
[外链图片转存中…(img-eaM1iDA3-1640918281707)]

本文已被CODING开源项目:《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》收录

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值