ActionBar重叠TextView,ConstraintLayout问题

问题描述 投票:0回答:1

ActionBar与TextView重叠。为什么?约束是正确的imho。它适用于RelativeLayout。我主要使用两个ConstraintLayout来添加一些不应该影响ActionBar的填充。

码:

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/my_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="#ffffff"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/constraintLayout2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingLeft="20dp"
        app:layout_constraintTop_toBottomOf="@+id/my_toolbar"
        android:layout_marginTop="10dp"
        android:paddingRight="20dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <TextView
            android:id="@+id/xxxx"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="xxxxxxx"
            android:textAppearance="?android:textAppearanceMedium"
            android:textColor="#000000"
            app:layout_constraintTop_toTopOf="@+id/constraintLayout2"
            app:layout_constraintStart_toStartOf="@+id/constraintLayout2"/>
android android-constraintlayout
1个回答
1
投票

将您的第二个ConstraintLayout高度更改为wrap_content,或者如果您想要全高,则将底部约束和高度设置为0dp,如下所示

enter image description here

 <androidx.constraintlayout.widget.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">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/my_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="#ffffff"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/constraintLayout2"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="10dp"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        app:layout_constraintTop_toBottomOf="@+id/my_toolbar"
        app:layout_constraintBottom_toBottomOf="parent">

        <TextView
            android:id="@+id/xxxx"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="xxxxxxx"
            android:textAppearance="?android:textAppearanceMedium"
            android:textColor="#000000"
            app:layout_constraintStart_toStartOf="@+id/constraintLayout2"
            app:layout_constraintTop_toTopOf="@+id/constraintLayout2" />
    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
© www.soinside.com 2019 - 2024. All rights reserved.