我正在开发一个Android项目,当用户上传图片时,我想显示一个进度条。但是,即使在设置show
进度条后,它也不起作用。我究竟做错了什么?Android:即使设置可见,进度条也不显示。
代码:
private ProgressBar spinner;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_restaurant_images);
spinner=(ProgressBar)findViewById(R.id.progressBar);
spinner.setVisibility(View.GONE);
// Rest of the non-relevant to problem code
}
private void uploadImage(boolean profilePhoto) {
spinner.setVisibility(View.VISIBLE);
if (!(reducedSizeBitmap == null)) {
reducedSizeBitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
this.restaurantService.addRestaurantImage(byteArray, profilePhoto);
}
spinner.setVisibility(View.GONE);
}
XML文件:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/restaurant_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top|center"
android:orientation="vertical">
<ImageView
android:id="@+id/userPhotoImageView"
android:layout_width="match_parent"
android:layout_height="436dp"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<internetlegion.com.restaurantlunchify.Templates.MaterialRippleLayout
style="@style/RippleStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginTop="54dp"
android:layout_marginRight="20dp"
android:layout_marginEnd="20dp"
app:rippleColor="@color/main_color_grey_400">
<internetlegion.com.restaurantlunchify.Templates.RobotoTextView
android:id="@+id/uploadUserImageButton"
style="@style/ButtonStyle.RaisedEmpty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/main_color_900"
android:minWidth="112dp"
android:layout_marginRight="20dp"
android:layout_marginEnd="20dp"
android:text="Upload"
android:textColor="#fff" />
</internetlegion.com.restaurantlunchify.Templates.MaterialRippleLayout>
<CheckBox
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:layout_marginRight="0dp"
android:layout_marginEnd="0dp"
android:layout_gravity="center_horizontal"
android:text="Default"
android:id="@+id/profilePhotoCheckBox"
android:checked="false" />
<internetlegion.com.restaurantlunchify.Templates.MaterialRippleLayout
style="@style/RippleStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginTop="54dp"
app:rippleColor="@color/main_color_grey_400">
<internetlegion.com.restaurantlunchify.Templates.RobotoTextView
android:id="@+id/userPhotoButtonSelect"
style="@style/ButtonStyle.RaisedEmpty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/main_color_900"
android:minWidth="112dp"
android:text="Capture"
android:textColor="#fff" />
</internetlegion.com.restaurantlunchify.Templates.MaterialRippleLayout>
</LinearLayout>
</LinearLayout>
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar"
android:progressDrawable="@drawable/circular_progress_bar"
android:layout_below="@+id/button"
android:layout_alignRight="@+id/textView"
android:layout_alignEnd="@+id/textView"
android:layout_alignLeft="@+id/textview"
android:layout_alignStart="@+id/textview"
android:layout_alignParentBottom="true" />
<ListView
android:id="@+id/restaurant_list_slidermenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:dividerHeight="1dp" />
</android.support.v4.widget.DrawerLayout>
图像是故意6MB左右,我正在上传到看到了吧,但它是不受待见。你能帮忙的话,我会很高兴。非常感谢。 :-)
@MikeM。 : 哪一个?我试了两次,没有帮助。 –
您确定您的代码中至少有一次对spinner.setVisibility(View.VISIBLE)的调用? –
@StefanWanitzek:是的,你可以在我上面发布的代码中看到,我有spinner.setVisibility(View.VISIBLE);我已将整个代码放在这里:http://pastebin.com/PbctN0ss以及XML。随时检查一下。谢谢... :-) –