2017-05-28 10 views
2

私はアンドロイド:layout_alignParentBottom = "true"を使用して、残りの利用可能な領域をボトムに取得するためのテキストビューを使用しました。相対レイアウトでは、alignParentBottomが使用されていますが、同じことを自分のコードの制約レイアウトで使用できますか?

これは、制約レイアウトでどのように使用可能なスペースを取得するためのテキストビューです。

ここでは同じ結果が得られない制約レイアウトに関連した変換を行います。

相対レイアウト

<TextView 
     android:id="@+id/tv1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Hello World!" 
/> 
    <TextView 
     android:layout_below="@id/tv1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#499989" 
     android:text="Hello World!" 
     android:layout_alignParentBottom="true" 
     /> 

enter image description here

答えて

1

あなたはちょうどそのようにそれを使用することができます:

<?xml version="1.0" encoding="utf-8"?><?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.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"> 

    <TextView 
     android:id="@+id/tv1" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:text="Hello World!" 
     app:layout_constraintEnd_toEndOf="parent" 
     app:layout_constraintStart_toStartOf="parent" /> 

    <TextView 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_below="@id/tv1" 
     android:background="#499989" 
     android:text="Hello World!" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintEnd_toEndOf="parent" 
     app:layout_constraintStart_toStartOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/tv1" 
     tools:layout_editor_absoluteX="0dp" /> 

</android.support.constraint.ConstraintLayout> 

app:layout_constraintEnd_toEndOfapp:layout_constraintStart_toStartOfmatch_parentのようなビューを作ることです。

app:layout_constraintTop_toBottomOf="@+id/tv1"したがって、ビューはtv1の下にあります。

そしてapp:layout_constraintBottom_toBottomOf="parent"ビューは、親(画面)

+0

の一番下までストレッチすることを助けてくれてありがとうです...しかし、これはただの下に2つ目のテキストビューをシフトしています。 – Swapnil

+0

しかし、これは動作していません。ちょうど2番目のテキストビューをbottomにシフトしています。私の2番目のテキストビューは、利用可能な完全なスペースを垂直に取得します。 – Swapnil

+0

私の回答を更新しました – motis10

関連する問題