2017-05-12 11 views
1

ConstraintLayoutにUIエレメントの上にランダムなスペースがある状況があります。画像では、textInputseekBar要素の上のスペースを参照してください。ConstraintLayoutの要素の上のスペース

タイプに基づいてカスタムフィールドのフォームを作成しています(例:数字入力、テキスト入力、スイッチなどがあります。受信したフィールドタイプとコンテンツのJSONArrayに基づいてフォームを動的に作成します。

数値入力、テキスト入力、スライダ(seekBar)の3種類を除いて、すべてが完全に構築されます。そのコードに何かがあった場合、これらの3つのタイプだけでなく、各フラグメントの上にこのスペースがあったと主張するので、私はフォームを生成するコードを提供していません。ここで

enter image description here

番号入力用のレイアウトファイル(それは入力タイプと要素のid以外のテキスト入力のための1と全く同じに見える)です:

<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" 
tools:context="our.package.name.custom_fields.type_slider.SliderFragment"> 

<TextView 
    android:id="@+id/displayText" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:textAppearance="@style/Base.TextAppearance.AppCompat.Subhead" 
    android:visibility="gone" 
    app:layout_constraintBottom_toBottomOf="parent" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toTopOf="parent" /> 

<android.support.design.widget.TextInputLayout 
    android:id="@+id/input_layout" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toBottomOf="@+id/displayText"> 

    <android.support.design.widget.TextInputEditText 
     android:id="@+id/number_input" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:inputType="number" /> 

</android.support.design.widget.TextInputLayout> 
</android.support.constraint.ConstraintLayout> 

そして、 SeekBarのレイアウトファイルは次のとおりです。

<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" 
tools:context="our.package.name.custom_fields.type_slider.SliderFragment"> 

<TextView 
    android:id="@+id/displayText" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:textAppearance="@style/Base.TextAppearance.AppCompat.Subhead" 
    app:layout_constraintBottom_toBottomOf="parent" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toTopOf="parent" /> 

<SeekBar 
    android:id="@+id/slider_view" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toBottomOf="@+id/displayText" /> 

</android.support.constraint.ConstraintLayout> 

アイデアはありますか?

答えて

1

解決策は、私は要素の連鎖だ道になってしまいました。

私はTextViewが "アンカー"だと思ったので、その上、左、右と下を親に制限しました。それから私はそれに他の要素を連鎖させました - TextInputLayoutの上部はTextViewの底に拘束されました。

これを変更したところ、スペースの問題は解決されました。

したがって、TextInputLayoutの上部、左、右および底部は親に制約され、TextViewの底部はTextInputLayoutに制限されます。

enter image description here

見よ:

<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="wrap_content" 
tools:context="our.package.name.custom_fields.type_slider.SliderFragment"> 

<TextView 
    android:id="@+id/displayText" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:textAppearance="@style/Base.TextAppearance.AppCompat.Subhead" 
    app:layout_constraintBottom_toTopOf="@+id/input_layout" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toTopOf="parent" /> 

<android.support.design.widget.TextInputLayout 
    android:id="@+id/input_layout" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintBottom_toBottomOf="parent"> 

    <android.support.design.widget.TextInputEditText 
     android:id="@+id/text_input" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:inputType="textCapSentences" /> 

</android.support.design.widget.TextInputLayout> 
</android.support.constraint.ConstraintLayout> 
1

あなたはTextViewを親の中心にして、TextInputLayoutから@+id/displayTextの下に尋ねました。
このコントローラの中心を変更してください:

<TextView 
    android:id="@+id/displayText" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:textAppearance="@style/Base.TextAppearance.AppCompat.Subhead" 
    android:visibility="gone" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" /> 
+0

確かにそれは溶液でした。私はあなたの答えを投稿した2分後に文字通り説明する私の答えを掲示したので、私は時間内にそれを見ませんでした。ごめんなさい! :| – marienke

+0

これは解決策ですか? – marienke

関連する問題