Прогрессбар не отображается, когда в TextView есть контент - PullRequest
0 голосов
/ 31 августа 2018

Я работаю с классом, который расширяет Dialog. Он должен отображать элемент progressbar. Иногда будет сообщение, иногда нет.

progressbar показывает, когда нет сообщения, но не показывает, когда есть сообщение, и я не понимаю, почему.

Вот код макета:

<TextView
    android:id="@+id/dialog_message"
    style="@style/arial"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginTop="20dp"
    android:layout_marginLeft="100dp"
    android:layout_marginRight="100dp"
    android:layout_marginBottom="20dp"
    android:text=""
    android:textAlignment="center"
    android:textColor="@android:color/white"
    android:textSize="18sp"
    />

<ProgressBar
    android:id="@+id/progress"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginBottom="30dp"
    android:layout_marginLeft="100dp"
    android:layout_marginRight="100dp"
    android:layout_marginTop="10dp"
    android:visibility="gone" />

Вот Java:

public void progressDialog () {    
    if(this.message.getText().length() > 0){
        message.setVisibility(View.VISIBLE);
    }else{
        message.setVisibility(View.GONE);
    }
    progress.setVisibility(View.VISIBLE);
    leftButton.setVisibility(View.GONE);
    rightButton.setVisibility(View.GONE);
}

Когда установлено message GONE, отображается индикатор выполнения, если установлено message VISIBLE, индикатор выполнения не отображается. Я предполагаю, что это как-то скрыто сообщением.

Я попытался переместить его в макете, так как этот вопрос может показаться необходимым ProgressBar не отображает , но безрезультатно.

Как заставить индикатор выполнения всегда отображаться при вызове progressDialog()?

Редактировать ***** Добавлен полный макет xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background="@drawable/dialog_background"
  android:orientation="vertical">

<TextView
    android:id="@+id/dialog_title"
    style="@style/arialBold"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginBottom="5dp"
    android:layout_marginTop="35dp"
    android:ellipsize="end"
    android:maxLines="1"
    android:text="@string/waiting"
    android:textColor="@android:color/white"
    android:textSize="21sp" />

<TextView
    android:id="@+id/dialog_message"
    style="@style/arial"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_margin="30dp"
    android:text=" "
    android:textAlignment="center"
    android:textColor="@android:color/white"
    android:textSize="20sp" />

<ProgressBar
    android:id="@+id/progress"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginBottom="30dp"
    android:layout_marginLeft="100dp"
    android:layout_marginRight="100dp"
    android:layout_marginTop="30dp"
    android:visibility="gone" />

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginBottom="30dp"
    android:orientation="horizontal">

    <LinearLayout
        android:id="@+id/dialog_button_one"
        style="@android:style/Widget.Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:background="@color/purple"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/dialog_button_one_text"
            style="@style/arialBold"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"

android:layout_marginLeft="@dimen/alert_dialog_button_margin_left_right"

android:layout_marginRight="@dimen/alert_dialog_button_margin_left_right"
            android:layout_marginTop="10dp"
            android:ellipsize="end"
            android:maxLines="1"

            android:textColor="@android:color/white"
            android:textSize="20sp" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/dialog_button_two"
        style="@android:style/Widget.Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginStart="20dp"
        android:background="@color/purple"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/dialog_button_two_text"
            style="@style/arialBold"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="@dimen/alert_dialog_button_margin_left_right"
            android:layout_marginRight="@dimen/alert_dialog_button_margin_left_right"
            android:layout_marginTop="10dp"
            android:ellipsize="end"
            android:maxLines="1"
            android:textColor="@android:color/white"
            android:textSize="20sp" />

    </LinearLayout>


 </LinearLayout>
</LinearLayout>

Ответы [ 3 ]

0 голосов
/ 03 сентября 2018

Добавьте родительский макет ограничений в линейный макет и переместите индикатор выполнения из линейного макета.

<constraint>
   <linear/>
   <progress/>
</constraint>

Примерно так:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/dialog_background"
        android:orientation="vertical"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent" 
    >


    <!-- Your complete layout -->

</LinearLayout>


    <ProgressBar
        android:id="@+id/progress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:visibility="gone" />

</android.support.constraint.ConstraintLayout>
0 голосов
/ 03 сентября 2018

Хорошо, похоже, вы используете какое-то неправильное свойство для того, что вы хотите, смотрите:

android: layout_gravity = "center" поместит ваш TextView в центр макета, но вы также установите его в ProgressBar , это означает, что только будет показан один из них, он полезен только в том случае, если вы хотите показывать по одному представлению за раз, если вы хотите показать оба, попробуйте удалить одно из этих свойств.

Другое дело, вы устанавливаете android: layout_margin = "30dp" в TextView, так что ваш progressBar будет далеко удален от TextView, что также может вызвать невидимость ProgressBar, попробуйте 16dp .

<TextView
android:id="@+id/dialog_message"
style="@style/arial"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" // remove here or in ProgressBar
android:layout_margin="16dp" // I just replace 30dp to 16dp
android:text=" "
android:textAlignment="center"
android:textColor="@android:color/white"
android:textSize="20sp" />

РЕДАКТИРОВАТЬ - Другой ответ

Я редактирую ваш полный XML-код, заменяя некоторые поля отступом, и всегда показываю индикатор выполнения. Теперь вы можете скрыть / показать textView или прогресс-бар, он должен работать.

Я также заменяю некоторые свойства, поскольку здесь их нет, не забудьте добавить еще раз. Надеюсь, это поможет вам.

Я рекомендую использовать RelativeLayout для улучшения вашего интерфейса. Ниже я показываю текущее поведение XML.

When ProgressBar is hided

Когда отображается ProgressBar

enter image description here

Полный исходный код по ссылке ниже, я не могу вставить код здесь.

https://gist.github.com/pedromassango/a6dc213823b297931f1ef2e6b6954466

0 голосов
/ 01 сентября 2018

Я думаю, что вы используете линейный макет. Поэтому используйте линейный макет вместо линейного макета.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...