2017-08-02 30 views
0

私はのTextViewを持っている:私は "トンをドンいくつかの時間がそれを必要とするので、私が欲しいもの制約レイアウト変更制約をプログラム

<TextView 
    android:id="@+id/textViewChat" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_marginEnd="8dp" 
    android:layout_marginLeft="8dp" 

    android:layout_marginRight="16dp" 
    android:layout_marginStart="8dp" 
    android:layout_marginTop="26dp" 
    android:background="@drawable/rounded_corner" 
    android:fontFamily="serif" 
    android:text="I have one listView " 
    android:textAlignment="textStart" 
    android:textColor="@color/bb_darkBackgroundColor" 
    android:textSize="15sp" 
    app:layout_constraintHorizontal_bias="0.0" 
    app:layout_constraintLeft_toRightOf="@+id/imageViewChat" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toTopOf="parent" 
    app:layout_constraintWidth_default="wrap"/> 

はプログラム的に最後の行を削除することです

答えて

1

ありがとうございます。私が理解していただきたいのは、app:layout_constraintWidth_default="wrap"app:layout_constraintWidth_default="spread"に変更することです。

次のコードは、01を使用する方法を示していますこれを行うにはが必要です。 XMLはあなたが提示したものですが、ConstraintLayoutにはconstraintLayoutのIDが与えられています。

このコードは、レイアウトに存在するすべての制約を取得し、目的の変更を行い、変更を再適用します。

protected void onCreate(Bundle savedInstanceState) { 
    final ConstraintSet cs = new ConstraintSet(); 
    ConstraintLayout layout; 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    layout = (ConstraintLayout) findViewById(R.id.constraintLayout); 
    cs.clone(this, R.layout.activity_main); 
    cs.constrainDefaultWidth(R.id.textViewChat, ConstraintSet.MATCH_CONSTRAINT_SPREAD); 
    cs.applyTo(layout); 
} 
関連する問題