如何在每个imageview中加载图片时显示进度条。我已经尝试了下面给出的代码
if (stage1ImageURL.startsWith("http://")) {
//Picasso.with(getActivity()).load(stage1ImageURL).into(stage1ImageView);
//imageLoader.DisplayImage((stage1ImageURL), stage1ImageView);
Picasso.with(getActivity())
.load(stage1ImageURL)
.into(stage1ImageView , new Callback() {
@Override
public void onSuccess() {
// TODO Auto-generated method stub
progressBar.setVisibility(View.GONE);
}
@Override
public void onError() {
// TODO Auto-generated method stub
}
});
}
答案 0 :(得分:2)
您可以使用Framelayout
换行重叠两个视图。只需打开进度条和ImageView
,如下所示。然后在View.VISIBLE
View.GONE
和onSuccess()
<Framelayout
android:id="@+id/myContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"/>
<ImageView
android:id="@+id/stage1ImageView"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:layout_margin="5dp"
android:paddingLeft="60dp"
android:scaleType="centerCrop"/>
</Framelayout>
答案 1 :(得分:0)
你的布局应该是这样的
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="50dp"
style="@android:style/Widget.ProgressBar.Small"
android:indeterminate="false"
android:visibility="visible"
android:progress="1" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp">
</ImageView>
</FrameLayout>
你的java文件中的代码看起来不错。首先使用findViewById
progressBar = (ProgressBar) findViewById(R.id.progressBar1);
然后使用progressBar.setVisibility(View.GONE)