#android #android-constraintlayout
#Android #android-constraintlayout
Вопрос:
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
она находится под MaterialButton
?
Комментарии:
1. Вы пытались установить
elevation
свойство на вашемProgressBar
компьютере?2. отсутствует ограничение макета под элементом
include layout="@layout/progress_bar_layout"...
3. @FonzTech Я использую «android: высота =»10dp» для панели прогресса. Это не помогает.
4. @jackycflau Что ты имеешь в виду?
5. отсутствуют ограничения для включенного макета, на что пытается указать @jackycflau. Это может быть причиной смещения индикатора выполнения.
Ответ №1:
У вас есть значение для индикатора выполнения, установленное на 10dp
, и это дает правильный ответ, но, поскольку индикатор выполнения встроен в ConstraintLayout
а ConstraintLayout
включен в другой макет, именно для ConstraintLayout
этого требуется значение.
Просто переместитесь android:elevation="10dp"
из ProgressBar
в ее окружение ConstraintLayout
.
Комментарии:
1. Как насчет Android 5.0? «android: повышение прав» только из API> = 21
2. @Alexey В таком случае убедитесь, что макет с индикатором выполнения включен после кнопки material. Виды отображаются в порядке их появления в макете (обычно), поэтому кнопка будет нарисована, а затем индикатор выполнения будет нарисован поверх нее.
3. @Alexey Если вы уберете высоту с кнопки, вы упустите один из «материальных» аспектов кнопки.
Ответ №2:
Чтобы сделать кнопку не поднятой, вы можете добавить атрибут стиля, как показано ниже:-
style="@style/Widget.MaterialComponents.Button.UnelevatedButton"