android - ConstraintLayout: Realign baseline constraint in case if dependent view visibility was set to GONE -


is there way realign baseline constraint textview in case if dependent view visibility set gone?

my layout code:

<android.support.constraint.constraintlayout     android:layout_width="match_parent"     android:layout_height="wrap_content">      <textview         android:id="@+id/title"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="test title"         android:textcolor="@color/black"         android:textsize="24sp"         app:layout_constraintleft_toleftof="parent"         app:layout_constraintright_torightof="parent"/>      <textview         android:id="@+id/subtitle1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="subtitle 1"         android:textsize="11sp"         app:layout_constraintbaseline_tobaselineof="@+id/subtitle2"         app:layout_constrainthorizontal_chainstyle="packed"         app:layout_constraintleft_toleftof="parent"         app:layout_constraintright_toleftof="@+id/subtitlespace"         app:layout_constraintright_torightof="parent"/>      <android.support.v4.widget.space         android:id="@+id/subtitlespace"         android:layout_width="12dp"         android:layout_height="wrap_content"         app:layout_constraintleft_torightof="@+id/subtitle1"         app:layout_constraintright_toleftof="@+id/subtitle2"/>      <textview         android:id="@+id/subtitle2"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_margintop="4dp"         android:text="subtitle 2"         android:textsize="14sp"         app:layout_constraintleft_torightof="@+id/subtitlespace"         app:layout_constraintright_torightof="parent"         app:layout_constrainttop_tobottomof="@+id/title"/>  </android.support.constraint.constraintlayout> 

in case, layout looks this: enter image description here

when i'm setting subtitle2 textview visibility gone layout this: enter image description here

so i'm wondering if there constraint can realign baseline in case if dependent view missing.

alternate margins can specified gone widgets (see margins when connected gone widget), not aware of such alternative baselines.

one way satisfy requirement specify 0dp invisible textview has same characterisics of gone textview placed next same view. subtitle1 , subtitle2 tie baseline of new textview. though new textview doesn't show on screen , takes 0 width, still maintains baseline.

now, when subtitle2 made gone, subtitle1 move center maintain vertical position. (specifying 0dp , invisible null text redundant makes clear widget should not appear.)

here xml these changes:

<android.support.constraint.constraintlayout xmlns:android="http://schemas.android.com/apk/res/android"     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="wrap_content">      <textview         android:id="@+id/title"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="test title"         android:textcolor="#ff000000"         android:textsize="24sp"         app:layout_constraintleft_toleftof="parent"         app:layout_constraintright_torightof="parent" />      <textview         android:id="@+id/subtitle1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="subtitle 1"         android:textsize="11sp"         app:layout_constraintbaseline_tobaselineof="@+id/viewforbaseline"         app:layout_constrainthorizontal_chainstyle="packed"         app:layout_constraintleft_toleftof="parent"         app:layout_constraintright_toleftof="@+id/subtitlespace"         app:layout_constraintright_torightof="parent" />      <android.support.v4.widget.space         android:id="@+id/subtitlespace"         android:layout_width="12dp"         android:layout_height="wrap_content"         app:layout_constraintleft_torightof="@+id/subtitle1"         app:layout_constraintright_toleftof="@+id/subtitle2" />      <textview         android:id="@+id/subtitle2"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_margintop="4dp"         android:text="subtitle 2"         android:textsize="14sp"         android:visibility="gone"         app:layout_constraintbaseline_tobaselineof="@+id/viewforbaseline"         app:layout_constraintleft_torightof="@+id/subtitlespace"         app:layout_constraintright_torightof="parent"         app:layout_constrainttop_tobottomof="@+id/title" />      <textview         android:id="@+id/viewforbaseline"         android:layout_width="0dp"         android:layout_height="wrap_content"         android:layout_margintop="4dp"         android:textsize="14sp"         android:visibility="invisible"         app:layout_constraintright_torightof="parent"         app:layout_constrainttop_tobottomof="@+id/title" />  </android.support.constraint.constraintlayout>  

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -