‘壹’ android中imageview更改图片图图不消失,导致原图片和后来设置的图片叠加到了一块,怎么办啊
你这是src属性和bakground属性叠加了
在布局文件中,把Imageview的background属性,改为src属性,就可以了
或者你把mview.setImageResource的方法改为mview.setBackground方法
‘贰’ android 如何实现图片视频混合播放啊
直接上代码:
布局文件就是两个全屏的videoview和imageview重叠
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/pictureView"
android:scaleType="fitXY"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
java部分:
/*
视频图片混合展示demo
*/
packagecom.example.administrator.hunbo;
importandroid.content.Context;
importandroid.media.MediaPlayer;
importandroid.net.Uri;
importandroid.os.Handler;
importandroid.os.storage.StorageManager;
importandroid.support.v7.app.AppCompatActivity;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.widget.ImageView;
importandroid.widget.Toast;
importandroid.widget.VideoView;
importjava.io.File;
importjava.lang.reflect.InvocationTargetException;
importjava.lang.reflect.Method;
importjava.util.ArrayList;
{
privateVideoViewvideoView;
privateImageViewpictureView;
booleanisPlaying=false;
privateArrayListarrayList=newArrayList<String>();
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().hide();//隐藏actionBar
//初始化控件
videoView=findViewById(R.id.videoView);
pictureView=findViewById(R.id.pictureView);
//最开始两个view都是隐藏的
videoView.setVisibility(View.GONE);
pictureView.setVisibility(View.GONE);
//检测SD卡是否存在
String[]result=null;
StorageManagerstorageManager=(StorageManager)getSystemService(Context.STORAGE_SERVICE);
try{
Methodmethod=StorageManager.class.getMethod("getVolumePaths");
method.setAccessible(true);
try{
result=(String[])method.invoke(storageManager);
}catch(InvocationTargetExceptione){
e.printStackTrace();
}
if(result.length>1){
//Toast.makeText(this,"检测到U盘",Toast.LENGTH_SHORT).show();
AllFilesPath("/mnt/usb/");
playList();
}else{
Toast.makeText(this,"未检测到U盘,请在开机前插入U盘,或者重新启动此应用",Toast.LENGTH_SHORT).show();
Handlerhandler=newHandler();
handler.postDelayed(newRunnable(){
@Override
publicvoidrun(){
finish();
}
},2500);
}
}catch(Exceptione){
e.printStackTrace();
}
}
//获取所有图片视频的绝对路径到arraylist
privateArrayListAllFilesPath(Stringpath){
Filefile=newFile(path);
File[]files=file.listFiles();
for(Filef:files){
if(f.getName().endsWith("jpg")||f.getName().endsWith("jpeg")||f.getName().endsWith("mp4")
||f.getName().endsWith("avi")||f.getName().endsWith("mkv")||f.getName().endsWith("rmvb")
||f.getName().endsWith("flv")){
System.out.println("------------获取到了一个可用路径:"+f.getAbsolutePath());
arrayList.add(f.getAbsolutePath());//添加到arralist
}elseif(f.isDirectory()){
AllFilesPath(f.getAbsolutePath());
}
}
returnarrayList;
}
//依次混合播放arralist里的图片或视频
publicintlistNum;
privatevoidplayList(){
if(listNum>=arrayList.size()){
finish();
//listNum=0;
}else{
System.out.println("---------------------------收入路径---------------------------");
System.out.println("isplaying="+isPlaying);
finalFilef=newFile(arrayList.get(listNum).toString());
if(f.getName().endsWith("jpg")||f.getName().endsWith("jpeg")||f.getName().endsWith("png")){
System.out.println("---------------------------添加了一张图片:"+f.getAbsolutePath());
pictureView.setVisibility(View.VISIBLE);
pictureView.setImageURI(Uri.fromFile(f));
Handlerhandler=newHandler();
handler.postDelayed(newRunnable(){
@Override
publicvoidrun(){
System.out.println("---------------------------播完了一张位于"+f.getAbsolutePath()+"的图片》》》》》》》》》》》》》》》》》");
pictureView.setVisibility(View.GONE);
listNum++;
playList();
}
},2000);//2秒后结束当前图片
}elseif(f.getName().endsWith("mp4")||f.getName().endsWith("avi")||f.getName().endsWith("mkv")
||f.getName().endsWith("rmvb")||f.getName().endsWith("flv")){
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~添加了一个视频"+f.getAbsolutePath());
videoView.setVideoPath(f.getAbsolutePath());
videoView.setVisibility(View.VISIBLE);//播放之前显示videoView
videoView.start();
videoView.setOnCompletionListener(newMediaPlayer.OnCompletionListener(){
@Override
publicvoidonCompletion(MediaPlayermp){
System.out.println("---------------------------播完了一个位于"+f.getAbsolutePath()+"的视频《《《《《《《《《《《《《《《《《《");
videoView.setVisibility(View.GONE);//视频播放完毕后隐藏videoView
listNum++;
playList();
}
});
}
}
}
‘叁’ Android:多张竖着的图片(一屏幕放不下)用什么实现
网络加载还是你直接写,1.不行就写个listview,2.非得放在一个屏幕里就linearlayout里边加权重weight=“1”,就可以了但是图片可能都是小小的。
方法一 就是item点击事件,然后switch(pos)case 0-5。方法二就是每一个都加id做点击事件。
还有一个办法,非要竖向单排么,可以竖向双排,或者竖向3排么,recycleview了解一下。 item事件需要自己写。