在结果显示之前添加加载,我将滑行用于图像显示 [英] add loading before the result show, i use glide for my image display
问题描述
请构造我的代码,我要在结果未准备好时加载图像.
please construct my code, i want a loading image while the result is not ready..
我将glide用于此代码.
i use glide for this code..
imageView = (ImageView) rootView.findViewById(R.id.imageView);
Glide.with(getActivity()).load("http://joehamirbalabadan.com/android/android/imghome/index1.png").diskCacheStrategy(DiskCacheStrategy.ALL).placeholder(R.drawable.indexloading).into(imageView);
imageView3 = (ImageView) rootView.findViewById(R.id.imageView3);
Glide.with(getActivity()).load("http://joehamirbalabadan.com/android/android/imghome/index3.png").diskCacheStrategy(DiskCacheStrategy.ALL).placeholder(R.drawable.indexloading).into(imageView3);
您可以在我的代码中看到,我使用占位符索引加载.
as you can see in my code, i use placeholder indexloading.
但是gif加载图像在占位符中不起作用.
but gif loading image is not working in placeholder.
请给我一个解决我的问题的示例代码.
please give me a sample code that solb my problem..
也可以在片段中工作的代码.
also code that work in a fragment..
这是完整的代码.
HomeFragment.java
package com.example.administrator.mosbeau;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
/**
* Created by Administrator on 9/7/2015.
*/
public class HomeFragment extends Fragment {
public static HomeFragment newInstance() {
HomeFragment fragment = new HomeFragment();
return fragment;
}
public HomeFragment () {
}
Boolean InternetAvailable = false;
Seocnd detectconnection;
ImageView imageView, imageView3;
ProgressBar progressBar;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.homelayout, container, false);
detectconnection = new Seocnd(getActivity());
InternetAvailable = detectconnection.InternetConnecting();
if (InternetAvailable) {
imageView = (ImageView) rootView.findViewById(R.id.imageView);
Glide.with(getActivity()).load("http://joehamirbalabadan.com/android/android/imghome/index1.png").diskCacheStrategy(DiskCacheStrategy.ALL).placeholder(R.drawable.indexloading).into(imageView);
imageView3 = (ImageView) rootView.findViewById(R.id.imageView3);
Glide.with(getActivity()).load("http://joehamirbalabadan.com/android/android/imghome/index3.png").diskCacheStrategy(DiskCacheStrategy.ALL).placeholder(R.drawable.indexloading).into(imageView3);
} else {
NointernetFragment fragment = new NointernetFragment();
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, fragment)
.commit();
}
return rootView;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
((MainActivity) activity).onSectionAttached(1);
}
}
推荐答案
我遇到了同样的问题.我通过使用picasso
库解决了它.在此处
I had same problem. I solved it by using picasso
library. find the download link here
然后尝试这个.
ProgressBar spinner = (ProgressBar) findViewById(R.id.loading);
spinner.setVisibility(View.VISIBLE);
Picasso.with(getApplicationContext())
.load((your URL)
.into(imageView, new Callback() {
@Override
public void onSuccess() {
spinner.setVisibility(View.GONE);
}
@Override
public void onError() {
spinner.setVisibility(View.GONE);
imageView
.setBackgroundResource(R.drawable.small_logo);
}
});
在这里,我将ImageView
和ProgressBar
(上面代码中的旋转器)包装在RelativeLayout
中.
Here I have wrap ImageView
and ProgressBar
(spinner in above code) in RelativeLayout
.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="1dip" >
<ImageView
android:id="@+id/imageView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:scaleType="fitXY" />
<ProgressBar
android:id="@+id/loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone" /></FrameLayout>
希望这对您有所帮助.
这篇关于在结果显示之前添加加载,我将滑行用于图像显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!