如何在不消失约束布局中的组件的情况下使用高程?
How to use an elevation without disappearing an component in a constraint layout?
我目前正在使用 android-studio 和 Kotlin 开发应用程序。
我想对具有重叠设计的约束布局中的视图使用海拔功能。
当我将海拔功能添加到视图时,海拔有效,但顶部重叠的组件消失了。 (喜欢 view_1 → view_2)
像这种情况,如何在组件不消失的情况下使用抬高功能?
view_1
view_2
代码如下:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<View
android:id="@+id/view"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHeight_percent="0.8"
app:layout_constraintWidth_percent="0.8"
android:background="@color/colorPrimary"
android:elevation="8dp"
/>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:text="TextView"
android:textSize="32sp"
/>
</android.support.constraint.ConstraintLayout>
Android 工作室:3.3.2
对于您的情况,只需将相同的高度添加到您的第二个视图即可:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<View
android:id="@+id/view"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHeight_percent="0.8"
app:layout_constraintWidth_percent="0.8"
android:background="@color/colorPrimary"
android:elevation="8dp"
/>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:text="TextView"
android:elevation="8dp"
android:textSize="32sp"/>
</android.support.constraint.ConstraintLayout>
您的两个视图都具有相同的高度,因此没有一个与另一个重叠。
看起来像这样:
我目前正在使用 android-studio 和 Kotlin 开发应用程序。
我想对具有重叠设计的约束布局中的视图使用海拔功能。
当我将海拔功能添加到视图时,海拔有效,但顶部重叠的组件消失了。 (喜欢 view_1 → view_2)
像这种情况,如何在组件不消失的情况下使用抬高功能?
view_1
view_2
代码如下:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<View
android:id="@+id/view"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHeight_percent="0.8"
app:layout_constraintWidth_percent="0.8"
android:background="@color/colorPrimary"
android:elevation="8dp"
/>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:text="TextView"
android:textSize="32sp"
/>
</android.support.constraint.ConstraintLayout>
Android 工作室:3.3.2
对于您的情况,只需将相同的高度添加到您的第二个视图即可:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<View
android:id="@+id/view"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHeight_percent="0.8"
app:layout_constraintWidth_percent="0.8"
android:background="@color/colorPrimary"
android:elevation="8dp"
/>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:text="TextView"
android:elevation="8dp"
android:textSize="32sp"/>
</android.support.constraint.ConstraintLayout>
您的两个视图都具有相同的高度,因此没有一个与另一个重叠。
看起来像这样: