按钮与ConstraintLayout中的TabLayout重叠

时间:2018-03-09 17:00:37

标签: android android-layout button android-tablayout android-constraintlayout

在Constraintlayout中,我使用指南显示tablayout和视图,tablayout覆盖10%,视图覆盖90%的屏幕。在选项卡上单击我想显示一些按钮,从屏幕的底部到55%,我使用另一个指南(对于小部件)为55%。

这是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">

    <android.support.constraint.ConstraintLayout
        android:id="@+id/cl"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <View
            android:id="@+id/view"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:background="#D3D3D3"
            app:layout_constraintBottom_toTopOf="@+id/glTabLayout"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@null"
            android:text="Button"
            android:drawableTop="@mipmap/ic_launcher"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintRight_toLeftOf="@+id/imageView"
            app:layout_constraintTop_toBottomOf="@+id/glWidgets" />

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@mipmap/ic_launcher"
            app:layout_constraintLeft_toRightOf="@+id/button"
            app:layout_constraintRight_toLeftOf="@+id/textView"
            app:layout_constraintTop_toBottomOf="@+id/glWidgets" />

        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/test"
            android:textColor="#ff0000"
            app:layout_constraintLeft_toRightOf="@+id/imageView"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/glWidgets" />

        <android.support.constraint.Guideline
            android:id="@+id/glTabLayout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintGuide_percent="0.90" />

        <android.support.constraint.Guideline
            android:id="@+id/glWidgets"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintGuide_percent="0.55" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:background="@android:color/white"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/glTabLayout"
            app:tabGravity="fill"
            app:tabMode="fixed"
            app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget" />

    </android.support.constraint.ConstraintLayout>

</layout>

在选择标签时的开始时,小部件将显示为第一个屏幕截图。但在其他选项卡上单击我希望这些小部件滑动/动画到底部,我将指南(对于小部件)从55%更改为90%,以便它隐藏在tablayout后面。

动画/更新指南的代码:

    ConstraintLayout constraintLayout = binding.cl;
    ConstraintSet constraintSet = new ConstraintSet();
    constraintSet.clone(constraintLayout);
    constraintSet.setGuidelinePercent(binding.glWidgets.getId(), percent);
    TransitionManager.beginDelayedTransition(constraintLayout);
    constraintSet.applyTo(constraintLayout);

现在,imageview,textview或其他普通视图隐藏在tablayout下方但按钮与tablayout重叠。我想要动画时按钮进入tablayout。附上截图以便更好地理解:

enter image description here enter image description here

1 个答案:

答案 0 :(得分:0)

您是否曾尝试将按钮转换为textView,只要您处于想要在视图顶部显示标签的模式?

  • 如果您不需要Button类,可以选择其他方式:

使用包含textview和imageview而不是按钮的布局(相对或线性)。

相关问题