7

ConstraintLayoutに3つのボタンを追加しました。これらのボタンを無効または有効にするボタンを追加しました。ConstraintLayoutで複数のビューをグループ化する方法

通常のLinearLayoutを使用していた場合。私はすべてのボタンをリニアレイアウトに入れ、その特定のレイアウトを有効または無効にすることができました。

しかし、ConstraintLayoutを使用しています。だから、私はこれらのボタンをすべて無効にしたり有効にしたりする必要があります。異なるビューをグループ化するにはConstraintLayoutの方法が必要であると思います。

親切ConstriantLayout

enter image description here

<Button 
     android:text="Button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/button" 
     android:layout_marginTop="16dp" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintBottom_toBottomOf="parent" 
     android:layout_marginBottom="16dp" 
     android:layout_marginStart="16dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     android:layout_marginLeft="16dp" /> 

    <Button 
     android:text="Button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/button2" 
     app:layout_constraintBottom_toBottomOf="parent" 
     android:layout_marginBottom="16dp" 
     android:layout_marginStart="8dp" 
     app:layout_constraintLeft_toRightOf="@+id/button" 
     android:layout_marginLeft="8dp" 
     app:layout_constraintTop_toTopOf="@+id/button" /> 

    <Button 
     android:text="Button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/button3" 
     app:layout_constraintTop_toTopOf="@+id/button2" 
     android:layout_marginEnd="16dp" 
     app:layout_constraintRight_toRightOf="parent" 
     android:layout_marginRight="16dp" 
     android:layout_marginStart="8dp" 
     app:layout_constraintLeft_toRightOf="@+id/button2" 
     android:layout_marginLeft="8dp" /> 
+0

Chainsがあなたに役立つかもしれません:https://developer.android.com/reference/android/support/constraint/ConstraintLayout.html#Chains – krossovochkin

答えて

1

のグループビューに現在あなたがそれを行うことができます方法はありませんどのように私を導きます。 constraintlayoutの各ウィジェットに制約が追加されるので、各ボタンを個別に無効にする必要があります。

ビューをグループ化するには、ビューグループを使用する必要がありますが、これは制約レイアウトのコンテキストでは意味がありません。制約レイアウトで編集

:1.1.0-β1、あなたはグループビューがandroid.support.constraint.Groupを使用することができます。

25

はい、あなたは線形レイアウトを使用して可視性を処理できますが、私は考えているビューを有効/無効にできないことを知っています。だから今ConstraintLayoutにも、我々はグループ

を使用してビューの特定のグループの可視性を扱うことができますこれは、現在ベータ版で あるConstraintLayoutに導入された新機能です。

以下の手順に従ってプロジェクトのアプリgardleの依存関係で、その後

allprojects { 
    repositories { 
     maven { url 'https://maven.google.com' } 
     jcenter() 
    } 
} 

次のようにプロジェクトのGradleファイルにMavenのサポートを追加するために、ベータConstraintLayoutを追加する方法

はConstarintLayoutライブラリの依存関係を追加

今あなたが従う

<android.support.constraint.Group 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     app:constraint_referenced_ids="button7,button3,button2" 
     android:id="@+id/group" /> 

app:constraint_referenced_ids="button7,button3,button2" 

グループの参照IDには、実行時間を扱いたいカンマ区切りのビューidを含ま

としてあなたConstraintLayoutでグループを追加する必要がありますしたがって、アクティビティでは、以下のようにグループをバインドして可視性を処理します。

import android.support.constraint.Group; //import statement in activity 

Group group=(Group)findViewById(R.id.group);//bind view from xml 
group.setVisibility(View.VISIBLE);//this will visible all views 
group.setVisibility(View.GONE);//this will set Gone to all views 
group.setVisibility(View.INVISIBLE);//this will set INVISIBLE to all view 
+1

グループの背景色を変更することはできますか? –

+0

@IbrahimDisouki私はそれが現在存在しないと思います、もし何か私はここで更新されますが見つかりました。 – Pavan

関連する問題