我的ProgressBar出现问题,希望您能帮助我解决它。
我的布局如下:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBackground"
tools:context=".Edition">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
...../>
<ImageView
android:id="@+id/picEdition"
android:contentDescription="@null"
app:layout_constrainedHeight="true"
app:layout_constrainedWidth="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="15dp"
app:layout_constraintBottom_toTopOf="@+id/editionScroll"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tool_bar_edition" />
<ProgressBar
android:id="@+id/editionProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleLarge"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@id/editionScroll"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tool_bar_edition"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<include layout="@layout/activity_info"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
而我尝试调用此ProgressBar的Java代码部分是:
private ProgressBar editionProgressBar;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edition);
mContext = this;
editionProgressBar = findViewById(R.id.editionProgressBar);
previewLia.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
editionProgressBar.setVisibility(View.VISIBLE);
try {
Bitmap confirmLiaBitmap = BitmapFactory.decodeStream(getApplicationContext().openFileInput("editableImage"+i));
editImageView.setImageBitmap(doLiaFilter(confirmLiaBitmap));
i = i + 1;
try {
Bitmap finalLiaBitmap = ((BitmapDrawable)editImageView.getDrawable()).getBitmap();
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
finalLiaBitmap.compress(Bitmap.CompressFormat.PNG, 100, bytes);
FileOutputStream fo = openFileOutput("editableImage"+i, Context.MODE_PRIVATE);
fo.write(bytes.toByteArray());
fo.close();
}catch (Exception e){
e.printStackTrace();
}
}catch (IOException e){
e.printStackTrace();
}
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
editionProgressBar.setVisibility(View.GONE);
}
});
}
但是,当我单击previewLia时,ProgressBar不会出现...,这真令人沮丧,因为在另一个活动中,我将相同的代码用于约束布局中,效果很好。
你知道哪里可能出问题了吗?
提前谢谢!
答案 0 :(得分:0)
我建议您使用RelativeLayout
和LinearLayout
使其简单。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBackground"
tools:context=".Edition">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
...../>
<ImageView
android:id="@+id/picEdition"
android:contentDescription="@null"
app:layout_constrainedHeight="true"
app:layout_constrainedWidth="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="15dp"/>
<include layout="@layout/activity_info"/>
</LinearLayout>
<ProgressBar
android:id="@+id/editionProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleLarge"
android:visibility="gone"
android:layout_centerInParent="true"/>
</RelativeLayout>
答案 1 :(得分:0)
最后,问题不在布局中,而是在Java中。
我解决了将setVisibility放入AsyncTask的问题。
感谢您的回答!