2

ボタンのクリック時にグループの可視性を設定しようとすると、ビューのvisibility.Using com.android.support.constraintに影響しません:constraint-layout:1.1.0 -β4。私は問題なく要素単位で設定しようとしましたが、グループでは成功しませんでした。制約グループで可視性を設定できません

マイMainActivity.kt

private fun toggleLoginUI(show: Boolean) { 
    if (show) { 
     group.visibility = VISIBLE 
    } else { 
     group.visibility = INVISIBLE 
    } 
} 

fun onClick(view: View) { 
    when (view.id) { 
     R.id.button -> toggleLoginUI(true) 
     R.id.button4 -> toggleLoginUI(false) 
    } 
} 

マイactivity_main.xml

<android.support.constraint.ConstraintLayout.. 

      <TextView 
       android:id="@+id/textView" 
... /> 

      <TextView 
       android:id="@+id/textView2" 
... /> 

      <Button 
       android:id="@+id/button" 
.../> 

      <Button 
       android:id="@+id/button4" 
... /> 


      <android.support.constraint.Group 
       android:id="@+id/group" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:visibility="visible" 
       app:constraint_referenced_ids="textView,textView2" /> 
      </android.support.constraint.ConstraintLayout> 
+0

は、[この](https://stackoverflow.com/を見て質問/ 44449495 /チェーンのグループのトグル表示 - 制約 - レイアウト内) –

+0

問題をログに与える –

+0

ログにエラーはありません。何もしません。 – SS2095

答えて

2

これは私のバグのようです。 GONEが動作しますが、INVISIBLEはありません。誰かが私の考えが間違っている場所に投稿できない限り、バグ報告の価値があるかもしれません。 (私はconstraint-layout:1.1.0-beta4を使用しています)

これまでのところ、グループ内のIDを明示的に取得し、取得した各ビューの可視性を設定する回避策があります。

MainActivity.kt内

private fun toggleLoginUI(show: Boolean) { 
    if (show) { 
     setGroupVisibility(mLayout, group, Group.VISIBLE) 
    } else { 
     setGroupVisibility(mLayout, group, Group.INVISIBLE) 
    } 
} 

private fun setGroupVisibility(layout: ConstraintLayout, group: Group, visibility: Int) { 
    val refIds = group.referencedIds 
    for (id in refIds) { 
     layout.findViewById<View>(id).visibility = visibility 
    } 
} 

mLayoutConstraintLayoutあります。

アップデート:ここでGONE作品から/に変更すると、予想通りという事実を活用して、別の回避策です:

private fun toggleLoginUI(show: Boolean) { 
    if (show) { 
     group.visibility = GONE 
     group.visibility = VISIBLE 
    } else { 
     group.visibility = GONE 
     group.visibility = INVISIBLE 
    } 
} 
+0

は動作しますが、要素をループする必要がない方法を望んでいました。 – SS2095

+0

@ SS2095バグであれば、将来のリリースを待たなければなりません。 (これはバグだと思う)これは、その機能が必要な場合には暫定的に行うことができます。 – Cheticamp

+0

@ SS2095回答に代わる回避策を追加しました。 – Cheticamp

0

ちょうどあなたがそれを変更することができ、フォロー行を追加します。 です。

group.visibility=ConstraintLayout.GONE 
+0

それは試してみてください。 –

+1

それはうまくいきます。 – SS2095

関連する問題