按钮下方的进度条显示

时间:2018-11-19 15:18:43

标签: android

Android Studio 3.1

minSdkVersion 21

这是我的布局xml:

<?xml version="1.0" encoding="utf-8"?>
<layout 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">

    <data>

        <variable
            name="handler"
            type="md.dotfinance.tm.android.ui.activity.AddTraderActivity" />

    </data>

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/common_gray_color_bg">

        <include
            android:id="@+id/jsonViewToolBar"
            layout="@layout/tool_bar"
            android:title='@{@string/add_trader}'
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/baseTextView"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/default_margin"
            android:layout_marginEnd="8dp"
            android:text="@string/base"
            android:textSize="13sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/jsonViewToolBar" />

        <EditText
            android:id="@+id/baseEditText"
            style="@style/textViewOneLine"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:textSize="20sp"
            app:layout_constraintEnd_toEndOf="@+id/baseTextView"
            app:layout_constraintStart_toStartOf="@+id/baseTextView"
            app:layout_constraintTop_toBottomOf="@+id/baseTextView" />

        <TextView
            android:id="@+id/quoteTextView"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/default_margin"
            android:text="@string/quote"
            android:textSize="13sp"
            app:layout_constraintEnd_toEndOf="@+id/baseTextView"
            app:layout_constraintStart_toStartOf="@+id/baseTextView"
            app:layout_constraintTop_toBottomOf="@+id/baseEditText" />

        <EditText
            android:id="@+id/quoteEditText"
            style="@style/textViewOneLine"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:textSize="13sp"
            app:layout_constraintEnd_toEndOf="@+id/baseTextView"
            app:layout_constraintStart_toStartOf="@+id/baseTextView"
            app:layout_constraintTop_toBottomOf="@+id/quoteTextView" />


        <Button
            android:id="@+id/startButton"
            android:layout_width="0dp"
            android:layout_height="@dimen/min_height"
            android:layout_marginTop="@dimen/default_margin"
            android:layout_marginBottom="@dimen/default_margin"
            android:background="@color/button_gray"
            android:text="@string/start"
            app:layout_constraintEnd_toEndOf="@+id/baseTextView"
            app:layout_constraintStart_toStartOf="@+id/baseTextView"
            app:layout_constraintTop_toBottomOf="@+id/quoteEditText" />

        <include
            layout="@layout/progress_bar_layout"
            android:visibility="gone" />

    </android.support.constraint.ConstraintLayout>

</layout>

这是我的progress_bar_layout.xml

<?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:id="@+id/containerProgressBarLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#4777"
    android:clickable="true"
    android:focusable="true">

    <ProgressBar
        android:id="@+id/progressBar"
        style="?android:attr/progressBarStyle"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:indeterminateTint="@color/colorPrimary"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

但是当我启动应用程序时,进度条是UNDER按钮。 enter image description here

但是我需要结束按钮。 我该怎么做?

3 个答案:

答案 0 :(得分:1)

尝试使用

  

  

android.support.constraint.ConstraintLayout

并添加

  

android:elevation =“ 30dp”

到RelativeLayout标签

答案 1 :(得分:0)

执行此操作的最佳方法是隐藏进度条或将其设为visibility="gone"。确保为它提供一个ID,以便可以调用它并使用按钮和文本视图隐藏其他布局。然后在处理特定请求时显示进度栏。使其不可见!!!

答案 2 :(得分:-1)

尝试

<?xml version="1.0" encoding="utf-8"?>
<layout 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">

    <data>

        <variable
            name="handler"
            type="md.dotfinance.tm.android.ui.activity.AddTraderActivity" />

    </data>

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <include
            layout="@layout/progress_bar_layout"
            android:visibility="gone"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    </android.support.constraint.ConstraintLayout>

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/common_gray_color_bg">

        <include
            android:id="@+id/jsonViewToolBar"
            layout="@layout/tool_bar"
            android:title='@{@string/add_trader}'
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/baseTextView"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/default_margin"
            android:layout_marginEnd="8dp"
            android:text="@string/base"
            android:textSize="13sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/jsonViewToolBar" />

        <EditText
            android:id="@+id/baseEditText"
            style="@style/textViewOneLine"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:textSize="20sp"
            app:layout_constraintEnd_toEndOf="@+id/baseTextView"
            app:layout_constraintStart_toStartOf="@+id/baseTextView"
            app:layout_constraintTop_toBottomOf="@+id/baseTextView" />

        <TextView
            android:id="@+id/quoteTextView"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/default_margin"
            android:text="@string/quote"
            android:textSize="13sp"
            app:layout_constraintEnd_toEndOf="@+id/baseTextView"
            app:layout_constraintStart_toStartOf="@+id/baseTextView"
            app:layout_constraintTop_toBottomOf="@+id/baseEditText" />

        <EditText
            android:id="@+id/quoteEditText"
            style="@style/textViewOneLine"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:textSize="13sp"
            app:layout_constraintEnd_toEndOf="@+id/baseTextView"
            app:layout_constraintStart_toStartOf="@+id/baseTextView"
            app:layout_constraintTop_toBottomOf="@+id/quoteTextView" />


        <Button
            android:id="@+id/startButton"
            android:layout_width="0dp"
            android:layout_height="@dimen/min_height"
            android:layout_marginTop="@dimen/default_margin"
            android:layout_marginBottom="@dimen/default_margin"
            android:background="@color/button_gray"
            android:text="@string/start"
            app:layout_constraintEnd_toEndOf="@+id/baseTextView"
            app:layout_constraintStart_toStartOf="@+id/baseTextView"
            app:layout_constraintTop_toBottomOf="@+id/quoteEditText" />


    </android.support.constraint.ConstraintLayout>

</layout>