Android Studio 3.2.1
在我的build.gradle中:
android {
dataBinding {
enabled = true
}
compileSdkVersion 28
defaultConfig {
minSdkVersion 18
targetSdkVersion 28
versionCode 6
versionName "0.0.6"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
我的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>
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<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="20sp"
app:layout_constraintEnd_toEndOf="@+id/baseTextView"
app:layout_constraintStart_toStartOf="@+id/baseTextView"
app:layout_constraintTop_toBottomOf="@+id/quoteTextView" />
<com.google.android.material.button.MaterialButton
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:gravity="center"
android:textAllCaps="true"
android:textSize="13sp"
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" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
此处 progress_bar_layout
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="@dimen/min_height"
android:layout_height="@dimen/min_height"
android:elevation="10dp"
android:indeterminateTint="@color/colorPrimary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
结果如下:
为什么ProgressBar
是 UNDER MaterialButton
吗?
答案 0 :(得分:1)
要制作按钮,未提升的按钮,可以添加如下样式属性:-
style="@style/Widget.MaterialComponents.Button.UnelevatedButton"
答案 1 :(得分:1)
您已将进度条的标高设置为10dp
,这是正确的答案,但是,因为进度条已嵌入ConstraintLayout
中,并且包含了ConstraintLayout
在另一种布局中,ConstraintLayout
需要海拔。
将android:elevation="10dp"
从ProgressBar
移至其封闭的ConstraintLayout
。