Android: How can i add a border around TextView responsive with last item inside

爷,独闯天下 提交于 2020-05-14 12:34:12

问题


I want a layout exactly like this:

enter image description here

what i want to do is when i click at black arrow the items inside are hidden, like this:

enter image description here

when i set to hide the items my border layout is not reducing because the height is fixed, look:

enter image description here

what i want to do is when i click on the black arrow the items inside will be hidden and the border layout is reduce too, anyone can help me?

i need a ConstraintLayout because de activity is very complex and have more code, this is my code if you want to check:

<?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"
    >

    <include layout="@layout/toolbar" />

    <!-- Dados do Condutor Field -->
    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/border_dados_condutor_layout"
        android:layout_width="0dp"
        android:layout_height="235dp"
        android:layout_marginTop="20dp"
        android:layout_marginStart="16dp"
        android:layout_marginEnd="16dp"
        android:paddingTop="24dp"
        android:paddingBottom="16dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/toolbar"
        android:background="@drawable/border_layout_custom"
        >

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/preenchimento_dados_condutor_layout"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:visibility="visible"
            android:layout_marginStart="16dp"
            android:layout_marginEnd="16dp"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            >

           <TextView
               android:id="@+id/txt_viatura_unidade_label"
               android:layout_width="0dp"
               android:layout_height="wrap_content"
               android:text="@string/txt_nome_condutor"
               style="@style/TxtLabelStyle_inside"
               app:layout_constraintTop_toTopOf="parent"
               app:layout_constraintStart_toStartOf="parent"
               app:layout_constraintEnd_toEndOf="parent"
               app:layout_constraintHorizontal_bias="0.0" />

            <EditText
                android:id="@+id/nome_condutor"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:background="@drawable/bg_border_edittext"
                android:layout_marginTop="2dp"
                app:layout_constraintStart_toStartOf="@id/txt_viatura_unidade_label"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/txt_viatura_unidade_label" />

            <TextView
                android:id="@+id/txt_unidade_condutor_label"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:text="@string/txt_unidade_condutor"
                android:layout_marginTop="24dp"
                app:layout_constraintStart_toStartOf="@id/txt_viatura_unidade_label"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintTop_toBottomOf="@+id/nome_condutor"
                style="@style/TxtLabelStyle_inside" />

            <EditText
                android:id="@+id/unidade_condutor"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="2dp"
                app:layout_constraintStart_toStartOf="@id/txt_viatura_unidade_label"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toBottomOf="@id/txt_unidade_condutor_label"
                android:background="@drawable/bg_border_edittext" />


            <TextView
                android:id="@+id/txt_celular_condutor_label"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:text="@string/txt_celular_label"
                android:layout_marginTop="24dp"
                app:layout_constraintStart_toStartOf="@id/txt_viatura_unidade_label"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintTop_toBottomOf="@+id/unidade_condutor"
                style="@style/TxtLabelStyle_inside" />

            <EditText
                android:id="@+id/celular_condutor"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="2dp"
                app:layout_constraintStart_toStartOf="@id/txt_viatura_unidade_label"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toBottomOf="@id/txt_celular_condutor_label"
                android:background="@drawable/bg_border_edittext" />



        </androidx.constraintlayout.widget.ConstraintLayout>


    </androidx.constraintlayout.widget.ConstraintLayout>

    <TextView
        android:id="@+id/txt_dados_condutor_label"
        style="@style/TxtLabelStyle"
        android:background="@android:color/white"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/txt_label_dados_condutor"
        app:layout_constraintTop_toTopOf="@id/border_dados_condutor_layout"
        app:layout_constraintBottom_toTopOf="@id/border_dados_condutor_layout"
        app:layout_constraintStart_toStartOf="@+id/border_dados_condutor_layout"
        android:layout_marginStart="8dp"
        android:paddingStart="4dp"
        />

    <ImageView
        android:id="@+id/imageOpen_dados_condutor_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/white"
        android:paddingStart="4dp"
        android:paddingEnd="8dp"
        android:visibility="visible"
        android:src="@drawable/ic_arrow_open"
        app:layout_constraintBottom_toBottomOf="@id/txt_dados_condutor_label"
        app:layout_constraintStart_toEndOf="@id/txt_dados_condutor_label"
        app:layout_constraintTop_toTopOf="@id/txt_dados_condutor_label" />

   <ImageView
       android:id="@+id/imageClosed_dados_condutor_label"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:background="@android:color/white"
       android:paddingStart="4dp"
       android:paddingEnd="8dp"
       android:visibility="gone"
       android:src="@drawable/ic_arrow_closed"
       app:layout_constraintBottom_toBottomOf="@id/txt_dados_condutor_label"
       app:layout_constraintStart_toEndOf="@id/txt_dados_condutor_label"
       app:layout_constraintTop_toTopOf="@id/txt_dados_condutor_label" />


    <!--  Dados da Viatura Field  -->
    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/border_dados_viatura_layout"
        android:layout_width="0dp"
        android:layout_height="235dp"
        android:layout_marginTop="20dp"
        android:layout_marginStart="16dp"
        android:layout_marginEnd="16dp"
        android:paddingTop="24dp"
        android:paddingBottom="16dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/border_dados_condutor_layout"
        android:background="@drawable/border_layout_custom"
        >

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/preenchimento_dados_viatura_layout"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:visibility="visible"
            android:layout_marginStart="16dp"
            android:layout_marginEnd="16dp"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            >

            <TextView
                android:id="@+id/txt_unidade_viatura_label"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:text="@string/txt_viatura_unidade_label"
                style="@style/TxtLabelStyle_inside"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.0" />

            <EditText
                android:id="@+id/unidade_viatura"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:background="@drawable/bg_border_edittext"
                android:layout_marginTop="2dp"
                app:layout_constraintStart_toStartOf="@+id/txt_unidade_viatura_label"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/txt_unidade_viatura_label" />

            <TextView
                android:id="@+id/txt_km_viatura_label"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:text="Kilometragem Atual"
                android:layout_marginTop="24dp"
                app:layout_constraintStart_toStartOf="@+id/txt_unidade_viatura_label"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintTop_toBottomOf="@+id/unidade_viatura"
                style="@style/TxtLabelStyle_inside" />

            <EditText
                android:id="@+id/km_viatura"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="2dp"
                app:layout_constraintStart_toStartOf="@id/txt_unidade_viatura_label"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toBottomOf="@id/txt_km_viatura_label"
                android:background="@drawable/bg_border_edittext" />


            <TextView
                android:id="@+id/txt_combustivel_viatura_label"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:text="Combustível Disponível"
                android:layout_marginTop="24dp"
                app:layout_constraintStart_toStartOf="@id/txt_unidade_viatura_label"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintTop_toBottomOf="@+id/km_viatura"
                style="@style/TxtLabelStyle_inside" />

            <EditText
                android:id="@+id/combustivel_viatura"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="2dp"
                app:layout_constraintStart_toStartOf="@id/txt_unidade_viatura_label"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toBottomOf="@id/txt_combustivel_viatura_label"
                android:background="@drawable/bg_border_edittext" />



        </androidx.constraintlayout.widget.ConstraintLayout>


    </androidx.constraintlayout.widget.ConstraintLayout>

    <TextView
        android:id="@+id/txt_dados_viatura_label"
        style="@style/TxtLabelStyle"
        android:background="@android:color/white"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Dados da Viatura"
        app:layout_constraintTop_toTopOf="@id/border_dados_viatura_layout"
        app:layout_constraintBottom_toTopOf="@id/border_dados_viatura_layout"
        app:layout_constraintStart_toStartOf="@+id/border_dados_viatura_layout"
        android:layout_marginStart="8dp"
        android:paddingStart="4dp"
        />

    <ImageView
        android:id="@+id/imageOpen_dados_viatura_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/white"
        android:paddingStart="4dp"
        android:paddingEnd="8dp"
        android:visibility="visible"
        android:src="@drawable/ic_arrow_open"
        app:layout_constraintBottom_toBottomOf="@id/txt_dados_viatura_label"
        app:layout_constraintStart_toEndOf="@id/txt_dados_viatura_label"
        app:layout_constraintTop_toTopOf="@id/txt_dados_viatura_label" />

    <ImageView
        android:id="@+id/imageClosed_dados_viatura_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/white"
        android:paddingStart="4dp"
        android:paddingEnd="8dp"
        android:visibility="gone"
        android:src="@drawable/ic_arrow_closed"
        app:layout_constraintBottom_toBottomOf="@id/txt_dados_viatura_label"
        app:layout_constraintStart_toEndOf="@id/txt_dados_viatura_label"
        app:layout_constraintTop_toTopOf="@id/txt_dados_viatura_label" />

</androidx.constraintlayout.widget.ConstraintLayout>

来源:https://stackoverflow.com/questions/61398289/android-how-can-i-add-a-border-around-textview-responsive-with-last-item-inside

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!