ProgressBar не отображается с раскладкой координатора - PullRequest
0 голосов
/ 14 октября 2019

У меня проблема с моим 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>

И часть кода Javaгде я пытаюсь вызвать ProgressBar:

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 не появляется ... и это так расстраивает, потому что в другой деятельности, где я использую тот жекод в макет ограничения, он работает отлично.

Есть идеи, в чем может быть проблема?

Заранее спасибо!

1 Ответ

0 голосов
/ 15 октября 2019

Я предлагаю вам сделать это проще, используя 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>
...