『壹』 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事件需要自己寫。