- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经按照本教程(“https://www.youtube.com/watch?v=Yt15bySZTf0”)生成了移动存储和 SD 卡中可用的视频列表,但是当我运行应用程序时,加载到第一个 Activity 需要大约 30 秒,即所有可用视频的列表,以及当回收器 View 可用并且我开始滚动时,滚动安静滞后,请帮助我解决这个问题,以下是我的应用程序的代码
video_list_items.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"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content" > <!--if you add match parent it will cause large spaces between files while scrolling-->
<android.support.v7.widget.CardView
android:id="@+id/videoCardView"
android:layout_width="match_parent"
android:layout_height="150dp"
app:cardElevation="3dp"
android:layout_gravity="center"
android:layout_margin="4dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="5">
<ImageView
android:id="@+id/VideoImageView"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="4"
android:scaleType="centerCrop"
android:layout_gravity="center"/>
<TextView
android:id="@+id/VideoTextView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="5dp"
android:maxLines="1"
android:text="File Name"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
VideoAdapter.java
import android.content.Context;
import android.graphics.Bitmap;
import android.media.ThumbnailUtils;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.hdvideoandaudioplayer.MainActivity;
import com.example.hdvideoandaudioplayer.R;
import java.io.File;
import java.util.ArrayList;
public class VideoAdapter extends RecyclerView.Adapter<VideoViewHolder> {
private Context context;
ArrayList<File> videoArrayList;
public VideoAdapter(Context context, ArrayList<File> videoArrayList) {
this.context = context;
this.videoArrayList = videoArrayList;
}
@Override
public VideoViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View vView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.video_list_items, viewGroup, false);
return new VideoViewHolder(vView);
}
@Override
public void onBindViewHolder(@NonNull VideoViewHolder videoViewHolder, int i) {
videoViewHolder.vTextView.setText(MainActivity.fileArrayList.get(i).getName());
Bitmap bitmapThumbnail = ThumbnailUtils.createVideoThumbnail(videoArrayList.get(i).getPath(), MediaStore.Video.Thumbnails.MINI_KIND);
videoViewHolder.vImageView.setImageBitmap(bitmapThumbnail);
}
@Override
public int getItemCount() {
if(videoArrayList.size()>0){
return videoArrayList.size();
}
else {
return 1;
}
}
}
class VideoViewHolder extends RecyclerView.ViewHolder {
TextView vTextView;
ImageView vImageView;
CardView vCardView;
public VideoViewHolder(@NonNull View itemView) {
super(itemView);
vTextView = itemView.findViewById(R.id.VideoTextView);
vImageView = itemView.findViewById(R.id.VideoImageView);
vCardView = itemView.findViewById(R.id.videoCardView);
}
}
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.support.v7.widget.RecyclerView
android:id="@+id/videoListRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</android.support.v7.widget.RecyclerView>
</LinearLayout>
MainActivity.java
package com.example.hdvideoandaudioplayer;
import android.Manifest;
import android.content.pm.PackageManager;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Toast;
import com.example.hdvideoandaudioplayer.Adapter.VideoAdapter;
import java.io.File;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
RecyclerView mRecyclerView;
VideoAdapter obj_VideoAdapter;
public static int REQUEST_PERMISSION = 1;
File directory;
boolean BOOLEAN_PERMISSION;
public static ArrayList<File> fileArrayList = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mRecyclerView = findViewById(R.id.videoListRecyclerView);
directory = new File("/mnt/");
GridLayoutManager gridLayoutManager = new GridLayoutManager(MainActivity.this, 2);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setItemViewCacheSize(20);
mRecyclerView.setLayoutManager(gridLayoutManager);
permissionForVideo();
}
private void permissionForVideo() {
if((ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)){
if((ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE))){
}
else {
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, REQUEST_PERMISSION);
}
} else{
BOOLEAN_PERMISSION = true;
getFile(directory);
obj_VideoAdapter = new VideoAdapter(getApplicationContext(), fileArrayList);
obj_VideoAdapter.setHasStableIds(true);
mRecyclerView.setAdapter(obj_VideoAdapter);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if(requestCode == REQUEST_PERMISSION){
if(grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED){
BOOLEAN_PERMISSION = true;
getFile(directory);
obj_VideoAdapter = new VideoAdapter(getApplicationContext(), fileArrayList);
mRecyclerView.setAdapter(obj_VideoAdapter);
} else{
Toast.makeText(this, "Please grant Permission", Toast.LENGTH_SHORT).show();
}
}
}
public ArrayList<File> getFile(File directory) {
File[] listFile = directory.listFiles();
if(listFile!=null && listFile.length>0){
for (File file : listFile) {
if (file.isDirectory()) {
getFile(file);
} else {
BOOLEAN_PERMISSION = false;
if (file.getName().endsWith(".mp4") || file.getName().endsWith(".m4a") || file.getName().endsWith(".m4v") || file.getName().endsWith(".f4a") || file.getName().endsWith(".f4v") || file.getName().endsWith(".mp4") || file.getName().endsWith(".m4b") || file.getName().endsWith(".m4r") || file.getName().endsWith(".mp4") || file.getName().endsWith(".f4b") || file.getName().endsWith(".mov") || file.getName().endsWith(".3gp") || file.getName().endsWith(".3gp2") || file.getName().endsWith(".3g2") || file.getName().endsWith(".3gpp") || file.getName().endsWith(".3gpp2") || file.getName().endsWith(".3gp") || file.getName().endsWith(".ogg") || file.getName().endsWith(".oga") || file.getName().endsWith(".ogv") || file.getName().endsWith(".ogx") || file.getName().endsWith(".wmv") || file.getName().endsWith(".wma") || file.getName().endsWith(".asf*") || file.getName().endsWith(".webm") || file.getName().endsWith(".flv") || file.getName().endsWith(".avi") || file.getName().endsWith(".mkv") || file.getName().endsWith(".flv") || file.getName().endsWith(".vob") || file.getName().endsWith(".drc") || file.getName().endsWith(".gif") || file.getName().endsWith(".gifv") || file.getName().endsWith(".mng") || file.getName().endsWith(".MTS") || file.getName().endsWith(".MT2S") || file.getName().endsWith(".TS") || file.getName().endsWith(".mov") || file.getName().endsWith(".qt") || file.getName().endsWith(".wmv") || file.getName().endsWith(".yuv") || file.getName().endsWith(".rm") || file.getName().endsWith(".mvb") || file.getName().endsWith(".amv") || file.getName().endsWith(".mpg") || file.getName().endsWith(".mp2") || file.getName().endsWith(".mpeg") || file.getName().endsWith(".mpe") || file.getName().endsWith(".mpv") || file.getName().endsWith(".xvi") || file.getName().endsWith(".mxf") || file.getName().endsWith(".roq") || file.getName().endsWith(".nsv") || file.getName().endsWith(".3gp")) {
for (int j = 0; j < fileArrayList.size(); j++) {
if (fileArrayList.get(j).getName().equals(file.getName())) {
BOOLEAN_PERMISSION = true;
}
}
if (BOOLEAN_PERMISSION) {
BOOLEAN_PERMISSION = false;
} else {
fileArrayList.add(file);
}
}
}
}
}
return fileArrayList;
}
}
最佳答案
滑动依赖
implementation 'com.github.bumptech.glide:glide:3.8.0'
然后你可以使用下面的代码
Glide.with(this).load(videoArrayList.get(i).
thumbnail(0.2f).into(videoViewHolder.vImageView)
0.2f是sizeMultiplier,您可以根据您的要求调整它。
关于java - 回收器 View 需要 30 秒才能加载,并且滚动时也会滞后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58362633/
SQLite、Content provider 和 Shared Preference 之间的所有已知区别。 但我想知道什么时候需要根据情况使用 SQLite 或 Content Provider 或
警告:我正在使用一个我无法完全控制的后端,所以我正在努力解决 Backbone 中的一些注意事项,这些注意事项可能在其他地方更好地解决......不幸的是,我别无选择,只能在这里处理它们! 所以,我的
我一整天都在挣扎。我的预输入搜索表达式与远程 json 数据完美配合。但是当我尝试使用相同的 json 数据作为预取数据时,建议为空。点击第一个标志后,我收到预定义消息“无法找到任何内容...”,结果
我正在制作一个模拟 NHL 选秀彩票的程序,其中屏幕右侧应该有一个 JTextField,并且在左侧绘制弹跳的选秀球。我创建了一个名为 Ball 的类,它实现了 Runnable,并在我的主 Draf
这个问题已经有答案了: How can I calculate a time span in Java and format the output? (18 个回答) 已关闭 9 年前。 这是我的代码
我有一个 ASP.NET Web API 应用程序在我的本地 IIS 实例上运行。 Web 应用程序配置有 CORS。我调用的 Web API 方法类似于: [POST("/API/{foo}/{ba
我将用户输入的时间和日期作为: DatePicker dp = (DatePicker) findViewById(R.id.datePicker); TimePicker tp = (TimePic
放宽“邻居”的标准是否足够,或者是否有其他标准行动可以采取? 最佳答案 如果所有相邻解决方案都是 Tabu,则听起来您的 Tabu 列表的大小太长或您的释放策略太严格。一个好的 Tabu 列表长度是
我正在阅读来自 cppreference 的代码示例: #include #include #include #include template void print_queue(T& q)
我快疯了,我试图理解工具提示的行为,但没有成功。 1. 第一个问题是当我尝试通过插件(按钮 1)在点击事件中使用它时 -> 如果您转到 Fiddle,您会在“内容”内看到该函数' 每次点击都会调用该属
我在功能组件中有以下代码: const [ folder, setFolder ] = useState([]); const folderData = useContext(FolderContex
我在使用预签名网址和 AFNetworking 3.0 从 S3 获取图像时遇到问题。我可以使用 NSMutableURLRequest 和 NSURLSession 获取图像,但是当我使用 AFHT
我正在使用 Oracle ojdbc 12 和 Java 8 处理 Oracle UCP 管理器的问题。当 UCP 池启动失败时,我希望关闭它创建的连接。 当池初始化期间遇到 ORA-02391:超过
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 9 年前。 Improve
引用这个plunker: https://plnkr.co/edit/GWsbdDWVvBYNMqyxzlLY?p=preview 我在 styles.css 文件和 src/app.ts 文件中指定
为什么我的条形这么细?我尝试将宽度设置为 1,它们变得非常厚。我不知道还能尝试什么。默认厚度为 0.8,这是应该的样子吗? import matplotlib.pyplot as plt import
当我编写时,查询按预期执行: SELECT id, day2.count - day1.count AS diff FROM day1 NATURAL JOIN day2; 但我真正想要的是右连接。当
我有以下时间数据: 0 08/01/16 13:07:46,335437 1 18/02/16 08:40:40,565575 2 14/01/16 22:2
一些背景知识 -我的 NodeJS 服务器在端口 3001 上运行,我的 React 应用程序在端口 3000 上运行。我在 React 应用程序 package.json 中设置了一个代理来代理对端
我面临着一个愚蠢的问题。我试图在我的 Angular 应用程序中延迟加载我的图像,我已经尝试过这个2: 但是他们都设置了 src attr 而不是 data-src,我在这里遗漏了什么吗?保留 d
我是一名优秀的程序员,十分优秀!