- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在我的应用程序中使用 ViewPager,它包含 7 个 fragment 。每个 fragment 包含许多图像。我想在 fragment 使用 Glide 加载图像时显示加载微调器(图像不是来自互联网!无需下载)。加载图像大约需要半秒钟,而且似乎有延迟。所以我想知道如何显示 Spinner Progress Bar。
主要 Activity .java :
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
setupViewPager(viewPager);
if (isRTL())
viewPager.setCurrentItem(7);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
tabLayout.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
}
tabLayout.setupWithViewPager(viewPager);
}
public static boolean isRTL() {
return isRTL(Locale.getDefault());
}
public static boolean isRTL(Locale locale) {
final int directionality = Character.getDirectionality(locale.getDisplayName().charAt(0));
return directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT ||
directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC;
}
private void setupViewPager(ViewPager viewPager) {
ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
if (isRTL()) {
// The view has RTL layout
adapter.addFragment(new S7(), getString(R.string.stage7));
adapter.addFragment(new S6(), getString(R.string.stage6));
adapter.addFragment(new S5(), getString(R.string.stage5));
adapter.addFragment(new S4(), getString(R.string.stage4));
adapter.addFragment(new S3(), getString(R.string.stage3));
adapter.addFragment(new S2(), getString(R.string.stage2));
adapter.addFragment(new S1(), getString(R.string.stage1));
adapter.addFragment(new Intro(), getString(R.string.Introduction));
} else {
// The view has LTR layout
adapter.addFragment(new Intro(), getString(R.string.Introduction));
adapter.addFragment(new S1(), getString(R.string.stage1));
adapter.addFragment(new S2(), getString(R.string.stage2));
adapter.addFragment(new S3(), getString(R.string.stage3));
adapter.addFragment(new S4(), getString(R.string.stage4));
adapter.addFragment(new S5(), getString(R.string.stage5));
adapter.addFragment(new S6(), getString(R.string.stage6));
adapter.addFragment(new S7(), getString(R.string.stage7));
}
viewPager.setAdapter(adapter);
}
class ViewPagerAdapter extends FragmentPagerAdapter {
private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();
public ViewPagerAdapter(FragmentManager manager) {
super(manager);
}
@Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}
@Override
public int getCount() {
return mFragmentList.size();
}
public void addFragment(Fragment fragment, String title) {
mFragmentList.add(fragment);
mFragmentTitleList.add(title);
}
@Override
public CharSequence getPageTitle(int position) {
return mFragmentTitleList.get(position);
}
}
fragment :
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
public class Intro extends Fragment {
public Intro() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_intro, container, false);
ImageView image1 = (ImageView)rootView.findViewById(R.id.imageView_S0P1);
ImageView image2 = (ImageView)rootView.findViewById(R.id.imageView_S0P2);
ImageView image3 = (ImageView)rootView.findViewById(R.id.imageView_S0P3);
ImageView image4 = (ImageView)rootView.findViewById(R.id.imageView_S0P4);
ImageView image5 = (ImageView)rootView.findViewById(R.id.imageView_S0P5);
ImageView image6 = (ImageView)rootView.findViewById(R.id.imageView_S0P6);
ImageView image7 = (ImageView)rootView.findViewById(R.id.imageView_S0P7);
ImageView image8 = (ImageView)rootView.findViewById(R.id.imageView_S0P8);
ImageView image9 = (ImageView)rootView.findViewById(R.id.imageView_S0P9);
ImageView image10 = (ImageView)rootView.findViewById(R.id.imageView_S0P10);
ImageView image11 = (ImageView)rootView.findViewById(R.id.imageView_S0P11);
ImageView image12 = (ImageView)rootView.findViewById(R.id.imageView_S0P12);
ImageView image13 = (ImageView)rootView.findViewById(R.id.imageView_S0P13);
if (image1.getDrawable()==null) {
Glide.with(rootView.getContext()).load(R.drawable.s0p1).asBitmap().into(image1);
Glide.with(rootView.getContext()).load(R.drawable.s0p2).asBitmap().into(image2);
Glide.with(rootView.getContext()).load(R.drawable.s0p3).asBitmap().into(image3);
Glide.with(rootView.getContext()).load(R.drawable.s0p4).asBitmap().into(image4);
Glide.with(rootView.getContext()).load(R.drawable.s0p5).asBitmap().into(image5);
Glide.with(rootView.getContext()).load(R.drawable.s0p6).asBitmap().into(image6);
Glide.with(rootView.getContext()).load(R.drawable.s0p7).asBitmap().into(image7);
Glide.with(rootView.getContext()).load(R.drawable.s0p8).asBitmap().into(image8);
Glide.with(rootView.getContext()).load(R.drawable.s0p9).asBitmap().into(image9);
Glide.with(rootView.getContext()).load(R.drawable.s0p10).asBitmap().into(image10);
Glide.with(rootView.getContext()).load(R.drawable.s0p11).asBitmap().into(image11);
Glide.with(rootView.getContext()).load(R.drawable.s0p12).asBitmap().into(image12);
Glide.with(rootView.getContext()).load(R.drawable.s0p13).asBitmap().into(image13);
}
// Inflate the layout for this fragment
return rootView;
}
}
fragment .xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="appinventor.ai_itiel_maimon.Rubiks_cube.Intro">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/banner_ad_height"
android:orientation="vertical">
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="40dp"
android:layout_height="40dp"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:id="@+id/imageView_S0P1"
android:contentDescription="@string/image_description"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:id="@+id/imageView_S0P2"
android:contentDescription="@string/image_description"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:id="@+id/imageView_S0P3"
android:contentDescription="@string/image_description"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:id="@+id/imageView_S0P4"
android:contentDescription="@string/image_description"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:id="@+id/imageView_S0P5"
android:contentDescription="@string/image_description"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:id="@+id/imageView_S0P6"
android:contentDescription="@string/image_description"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:id="@+id/imageView_S0P7"
android:contentDescription="@string/image_description"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:id="@+id/imageView_S0P8"
android:contentDescription="@string/image_description"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:id="@+id/imageView_S0P9"
android:contentDescription="@string/image_description"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:id="@+id/imageView_S0P10"
android:contentDescription="@string/image_description"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:id="@+id/imageView_S0P11"
android:contentDescription="@string/image_description"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:id="@+id/imageView_S0P12"
android:contentDescription="@string/image_description"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:id="@+id/imageView_S0P13"
android:contentDescription="@string/image_description"/>
</LinearLayout>
</ScrollView>
我应该把 ProgressBar 放在哪里,怎么放?
非常感谢!!!
最佳答案
这只是微不足道的解决方案。您可以像这样将您的图像与进度条相关联(由 RelativeLayot 包装)。
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="appinventor.ai_itiel_maimon.Rubiks_cube.Intro">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/banner_ad_height"
android:orientation="vertical">
<!-- IMAGE 1 -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ProgressBar
android:id="@+id/pb1"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerInParent="true" />
<ImageView
android:id="@+id/imageView_S0P1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_centerInParent="true"
android:scaleType="centerCrop" />
</RelativeLayout>
<!-- IMAGE 2 -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ProgressBar
android:id="@+id/pb2"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerInParent="true" />
<ImageView
android:id="@+id/imageView_S0P2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_centerInParent="true"
android:scaleType="centerCrop" />
</RelativeLayout>
......... and so on .....
</LinearLayout>
</ScrollView>
用如下所示的静态方法创建辅助类会很有帮助。当您对 Glide 配置进行更改时,这对您有帮助。
public class ImageLoader{
public static showImage(ImageView imageView, ProgressBar progressBar){
Glide.with(mActivity).load(imagePath).asBitmap().listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
//handle error
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
progressBar.setVisibility(View.GONE);
return false;
}
}).into(imageView);
}
}
然后在您的 Activity 上调用该方法以显示每张图片。
ImageView image1 = (ImageView)rootView.findViewById(R.id.imageView_S0P1);
ProgressBar pb1 = (ProgressBar)rootView.findViewById(R.id.pb1);
ImageLoader.showImage(image1, pb1);
ImageLoader.showImage(image2, pb2);
... and so on....
关于android - 如何在 fragment 加载图像时制作 Progress Bar Spinner(使用 Glide)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37748508/
鉴于 foo.bar是一个模块,有什么区别 import foo.bar as bar 和 from foo import bar 我对延迟导入模块对此有何影响特别感兴趣。 注意:这不是 this q
我正在寻找一个选项来创建组合了 1 个条形图(每个索引)和 2 个条形图的条形图。 像这样: 我可以假装制作一个 2 条形图,将 0 放入第一组条形图,然后手动绘制一个条形图……但是有更优雅的方法吗?
这只是编写相同代码的两种方式吗?有什么我应该注意的功能差异吗? >>> a = 'foo' >>> if not a == 'bar': ... 'its not' ... 'its not'
通常条形图中的条形并排对齐。我怎样才能让它们位于前一个之上?所以我会考虑创建我已经拥有的系列并将它们添加到渲染器,但告诉渲染器将新系列放在现有系列之上,而不是将其放在现有系列旁边。仅计算最大值并仅显示
我试图在 Amchart 4 中点击条形图/列时突出显示条形图/列。使用下面的代码,我正在获取当前点击的条形图/列的值,但使用的是 column.isActive 属性,条形/列未突出显示。 我找到了
我正在名为“tests”的文件夹中处理大量 qunit 单元测试。每个文件的顶部如下所示,例如: moduleFor('mixin:foo') // or moduleFor('route:bar')
我在 pyTorch 和 matplotlib 中看到了这个约定: import torch.nn as nn import torch.optim as optim import matplotli
与我的示例平行的是,我正在构建一个游戏并有一个名为 player.lua 的类。 几周前我编写了这个代码,当时我还不太了解 Lua 的工作原理,所以我没有为播放器构建的表格。 我已经为玩家分配了各种属
一个简单的例子: void foo(class Bar * bar) { foo2(bar); } void foo2(Bar * bar) { bar->a++; } foo2 中使
原始需求:我想实现一个将Foo::*转换为Bar::*的宏。 伪代码将如下所示: macro_rules! convert_foo_to_bar { ($v: ty, $p: path) =>
出于好奇。我检查某个字符串是否超过指定的最大长度: var name = "This Is a Name"; if (!name.length >= 10) { //valid length
之间有什么区别 export * as bar from 'foo' 和 export { default as bar } from 'foo' 在我的特殊情况下,我尝试了以下两种方法,它们都有效,
以下代码会返回错误, $ perl -E'sub foo { my $bar if 0; $bar++ }' This use of my() in false conditional is no l
我需要知道一些语言提供的这个很酷的特性的正确名称。 仅供引用:在某些语言中,可以通过将值结构分配给“变量”结构来进行多重分配。在问题标题的示例中,它将“foo”分配给 foo,将“bar”分配给 ba
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: What is the difference between object keys with quotes
我们要搜索一个文件以找到前面没有“foo”的“bar”的所有实例(忽略前面的空格和后面的任何内容。) 所以如果我们有 foo foo bar baz bar a bunch of monkey
这是一个 SSCCE : import java.util.*; class Test { public static void main(String[] args) { b
我正在开发一个插件,该插件将添加到外部站点,例如 Meebo/Wibiya 栏。我正在研究如何对我的文件进行版本控制。 我想要实现的目标: 网站只需添加几行到他们的网站。 如果我选择的话,我将能够以静
我需要在没有省略号的情况下显示标签中的所有文本,但我无法预测标签将占用的行数。 是否可以在每个标签和展示之间留出一些边距中心的条与标签对齐? (有或没有改变每条之间的距离) 是否可以计算每个条之间的距
1. struct thread_args { 2. int thread_id; 3. struct timeval before; 4. struct timeval after
我是一名优秀的程序员,十分优秀!