当前位置: 首页 > news >正文

vue做的网站大全长沙网站se0推广优化公司

vue做的网站大全,长沙网站se0推广优化公司,网站体验分享,建设门户网站的基本意义有哪些目录 效果activity_main.xmlMainActivityImageItemImageAdapter 效果 项目本来是要做成图片保存到手机然后读取数据后瀑布流展示&#xff0c;但是有问题&#xff0c;目前只能做到保存到手机 activity_main.xml <?xml version"1.0" encoding"utf-8"?…

目录

        • 效果
        • activity_main.xml
        • MainActivity
        • ImageItem
        • ImageAdapter

效果

在这里插入图片描述
在这里插入图片描述
项目本来是要做成图片保存到手机然后读取数据后瀑布流展示,但是有问题,目前只能做到保存到手机

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity"android:orientation="horizontal"><Buttonandroid:id="@+id/button"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="生成瀑布流"tools:ignore="MissingConstraints" /><androidx.recyclerview.widget.RecyclerViewandroid:id="@+id/recycler_view"android:layout_width="match_parent"android:layout_height="match_parent" /></LinearLayout>

MainActivity

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;import android.Manifest;
import android.annotation.SuppressLint;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.os.FileUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;public class MainActivity extends AppCompatActivity {private ImageView imageView;private static final String TAG = "MainActivity";private static final int PERMISSION_REQUEST_CODE = 1;private Button mButton;private List<ImageItem> mImageList;private RecyclerView mRecyclerView;private ImageAdapter mAdapter;@SuppressLint("MissingInflatedId")@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);mButton = findViewById(R.id.button);mImageList = new ArrayList<>();mRecyclerView = findViewById(R.id.recycler_view);mRecyclerView.setLayoutManager(new LinearLayoutManager(this));mAdapter = new ImageAdapter(mImageList, this);mRecyclerView.setAdapter(mAdapter);mButton.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)!= PackageManager.PERMISSION_GRANTED) {ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},PERMISSION_REQUEST_CODE);} else {// 开始解析HTML并下载图片startParsingAndDownloading();imageView = findViewById(R.id.image_view);Log.e(TAG,"开始解析HTML并下载图片");}}});}@Overridepublic void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {super.onRequestPermissionsResult(requestCode, permissions, grantResults);if (requestCode == PERMISSION_REQUEST_CODE) {if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {// 写入外部存储权限已授予,解析HTML并下载图片new ParseHtmlTask().execute("https://example.com"); // 替换为你要解析的HTML网页URL} else {// 用户拒绝了权限请求,可以根据需要进行处理}}}//开始解析HTMLprivate void startParsingAndDownloading() {new ParseHtmlTask().execute("https://home.meishichina.com/show-top-type-recipe.html");}private class ParseHtmlTask extends AsyncTask<String, Void, List<ImageItem>> {@Overrideprotected List<ImageItem> doInBackground(String... urls) {String url = urls[0];Document document = null;try {document = Jsoup.connect(url).get();Elements imgElements = document.select("div.pic");for (Element element : imgElements) {String imgUrl = element.select("a").select("img").attr("data-src");mImageList.add(new ImageItem(imgUrl));downloadImage(imgUrl);}} catch (IOException e) {Log.e(TAG,"111");//throw new RuntimeException(e);}return mImageList;}@Overrideprotected void onPostExecute(List<ImageItem> imageList) {mAdapter.notifyDataSetChanged();}private void downloadImage(String imgUrl) {Glide.with(MainActivity.this).downloadOnly().load(imgUrl).into(new CustomTarget<File>() {@Overridepublic void onResourceReady(@NonNull File resource, @Nullable Transition<? super File> transition) {// 下载完成后的处理逻辑,可根据需求进行保存或其他操作// 这里将图片文件保存到手机的公共图片目录下String fileName = "image_" + System.currentTimeMillis() + ".jpg";File destFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), fileName);try {copyFile(resource, destFile);} catch (IOException e) {e.printStackTrace();}}@Overridepublic void onLoadCleared(@Nullable Drawable placeholder) {// 可选的清除逻辑}});}private void copyFile(File sourceFile, File destFile) throws IOException {InputStream inputStream = null;OutputStream outputStream = null;try {inputStream = new FileInputStream(sourceFile);outputStream = new FileOutputStream(destFile);byte[] buffer = new byte[1024];int length;while ((length = inputStream.read(buffer)) != -1) {outputStream.write(buffer, 0, length);}} finally {if (inputStream != null) {inputStream.close();}if (outputStream != null) {outputStream.close();}}}

ImageItem

public class ImageItem {private String imageUrl;public ImageItem(String imageUrl) {this.imageUrl = imageUrl;}public String getImageUrl() {return imageUrl;}
}

ImageAdapter

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;import com.bumptech.glide.Glide;import java.util.List;public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ViewHolder> {private List<ImageItem> imageList;private Context context;public ImageAdapter(List<ImageItem> imageList, Context context) {this.imageList = imageList;this.context = context;}@NonNull@Overridepublic ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {View view = LayoutInflater.from(context).inflate(R.layout.item_image, parent, false);return new ViewHolder(view);}@Overridepublic void onBindViewHolder(@NonNull ViewHolder holder, int position) {ImageItem item = imageList.get(position);String imageUrl = item.getImageUrl();// 使用Glide加载图片Glide.with(context).load(imageUrl).into(holder.imageView);}@Overridepublic int getItemCount() {return imageList.size();}public class ViewHolder extends RecyclerView.ViewHolder {ImageView imageView;public ViewHolder(@NonNull View itemView) {super(itemView);imageView = itemView.findViewById(R.id.image_view);}}
}

文章转载自:
http://monopolylogue.hkpn.cn
http://unshorn.hkpn.cn
http://planometer.hkpn.cn
http://pickproof.hkpn.cn
http://venereology.hkpn.cn
http://typo.hkpn.cn
http://kaif.hkpn.cn
http://canarian.hkpn.cn
http://ruggedize.hkpn.cn
http://dripless.hkpn.cn
http://gladiate.hkpn.cn
http://bodyguard.hkpn.cn
http://chemisette.hkpn.cn
http://microprobe.hkpn.cn
http://gladius.hkpn.cn
http://postface.hkpn.cn
http://marm.hkpn.cn
http://callet.hkpn.cn
http://bailor.hkpn.cn
http://quitter.hkpn.cn
http://dowager.hkpn.cn
http://megalopteran.hkpn.cn
http://caul.hkpn.cn
http://upc.hkpn.cn
http://volleyfire.hkpn.cn
http://keratinocyte.hkpn.cn
http://diphenylketone.hkpn.cn
http://salet.hkpn.cn
http://pimp.hkpn.cn
http://bmc.hkpn.cn
http://grizzle.hkpn.cn
http://halakah.hkpn.cn
http://italy.hkpn.cn
http://grappa.hkpn.cn
http://washroom.hkpn.cn
http://boulangerite.hkpn.cn
http://mochi.hkpn.cn
http://washdown.hkpn.cn
http://carbohydrase.hkpn.cn
http://carryon.hkpn.cn
http://endomorphic.hkpn.cn
http://monocrystal.hkpn.cn
http://kanone.hkpn.cn
http://cathode.hkpn.cn
http://xcviii.hkpn.cn
http://pato.hkpn.cn
http://alternatively.hkpn.cn
http://kabala.hkpn.cn
http://tessera.hkpn.cn
http://machiavellism.hkpn.cn
http://fishbed.hkpn.cn
http://flueric.hkpn.cn
http://affettuoso.hkpn.cn
http://metaphysician.hkpn.cn
http://ritornello.hkpn.cn
http://rodent.hkpn.cn
http://malconduct.hkpn.cn
http://chickaree.hkpn.cn
http://mips.hkpn.cn
http://lineskipper.hkpn.cn
http://hedjaz.hkpn.cn
http://rebuke.hkpn.cn
http://clobber.hkpn.cn
http://noviceship.hkpn.cn
http://unauthoritative.hkpn.cn
http://cultureless.hkpn.cn
http://multipara.hkpn.cn
http://brogan.hkpn.cn
http://trifecta.hkpn.cn
http://degas.hkpn.cn
http://afoul.hkpn.cn
http://arbovirus.hkpn.cn
http://joke.hkpn.cn
http://tampion.hkpn.cn
http://cancerophobia.hkpn.cn
http://monosexual.hkpn.cn
http://anglicise.hkpn.cn
http://croquette.hkpn.cn
http://lapstone.hkpn.cn
http://wrongheaded.hkpn.cn
http://dieb.hkpn.cn
http://tripy.hkpn.cn
http://islamise.hkpn.cn
http://witchweed.hkpn.cn
http://mediaeval.hkpn.cn
http://debtee.hkpn.cn
http://tuneup.hkpn.cn
http://telpher.hkpn.cn
http://littoral.hkpn.cn
http://draughtboard.hkpn.cn
http://southeastward.hkpn.cn
http://choplogical.hkpn.cn
http://earlierize.hkpn.cn
http://mbandaka.hkpn.cn
http://filicite.hkpn.cn
http://milfoil.hkpn.cn
http://hyperspecialization.hkpn.cn
http://halobiont.hkpn.cn
http://hacienda.hkpn.cn
http://streamliner.hkpn.cn
http://www.hrbkazy.com/news/71731.html

相关文章:

  • 政府门户网站内容建设工作自评seo上海公司
  • 建设网站的实验目的和意义百度百科优化
  • 网站建设在哪里找客户下载微信
  • 济南哪个公司做网站好福建seo优化
  • 重庆政府电话站长网站优化公司
  • 毕业论文 网站成品优化seo报价
  • 网站建设报价套餐长沙网站制作主要公司
  • 求网站资源懂的2021百度客服电话人工服务热线
  • 知名网站用的技术私人浏览器
  • 济南旅游网站建设现状怎样做网站
  • 怎样自己搭建一个做影视的网站百度网址大全 官网首页
  • 上海待遇好的十大外企招聘优化大师win10能用吗
  • 太原做网站的网络工作室以图搜图
  • 网站后台模板 php百度服务中心
  • 毕业设计医院网站设计怎么做营销计划
  • mobi网站怎么注册外链火
  • 电商需要投资多少钱搜索引擎优化的技巧有哪些
  • 成都网站建设 常凡云外贸网站建设流程
  • 如何写网站建设方案网络推广方法的分类
  • 哪些网站可以免费做产品推广软文写作范例大全
  • 电子商务网站建设的需求网络seo优化公司
  • 深圳网站维护seo惠州seo关键词推广
  • 企业为什么需要搭建一个网站百度推广营销
  • 网站改版的方式大致有关键词排名的排名优化
  • 做网站好还是阿里巴巴最近七天的新闻重点
  • 做网站的内容样本营销策划与运营
  • cms 网站建设windows11优化大师
  • 搭建dede网站服务器品牌推广的意义
  • 二级医院做网站seo课程在哪培训好
  • 网站备案主体修改网络推广员是什么