2017-09-15 8 views
2

これは私のXML for my activityです。問題を学習制約のレイアウトにする

<?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" 
    tools:context="com.example.xxx.listview.MainActivity"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="0dp" 
     android:layout_height="120dp" 
     android:background="@android:color/holo_red_light" 
     android:minHeight="?attr/actionBarSize" 
     android:theme="?attr/actionBarTheme" 
     app:layout_constraintBottom_toTopOf="@+id/main_listview" 
     app:layout_constraintEnd_toEndOf="parent" 
     app:layout_constraintStart_toStartOf="parent" 
     app:layout_constraintTop_toTopOf="parent" /> 

    <ListView 
     android:id="@+id/main_listview" 
     android:layout_width="wrap_content" 
     android:layout_height="0dp" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     tools:layout_constraintBottom_creator="1" 
     tools:layout_constraintLeft_creator="1" 
     tools:layout_constraintRight_creator="1" 
     tools:layout_constraintTop_creator="1"></ListView> 


</android.support.constraint.ConstraintLayout> 

ここで私は結局のことです。ちょうど私が制約事に新たなんだので、学習

What the look looks like when rendered in the emulator.

。彼らは私のiOSの生活と少し違って働き、学びたいと思っています。

答えて

0

のように使用する必要が

  • (心の中で制約クマを使用することによって、我々は4-constraintstop,bottom,left and Rightをした)、これを試してくださいエラーが発生しました。 >あなたのListViewwrap_contentなる高さと揃えます下 - あなたのListViewconstraintTopを逃している

    1. :私はあなたのレイアウトでいくつかの問題を見ました。
    2. あなたが言うあなたのToolBarconstraintTopParentへとconstraintBottomListViewへ - >あなたのToolBarトップListViewとトップParentの真ん中にある理由が理由です。

    ちょうどあなたtoolBarconstraintBottomを削除し、ツールバーの下にListViewconstraintTopを追加し、あなたの問題を解決します。

  • 0

    あなたListViewは、その上に制約が欠落しています。

    app:layout_constraintTop_toBottomOf="@+id/toolbar" 
    

    レイアウトツールは、あなたの高さは0dpあるので、それが再配置されるか、間違ったサイズになりますあなたを伝えるどこかに警告を表示する必要があります。別の制約を追加するように指示します。

    高さが0の場合は、ビューの上部と下部に制約が必要です。幅が0の場合は、ビューの左右に拘束が必要です。

    0
    • あなたは、私たちはもちろんその

    <?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" 
    android:id="@+id/cl_layout" 
    tools:context="com.example.xxx.listview.MainActivity"> 
    
    <android.support.v7.widget.Toolbar 
        android:id="@+id/toolbar" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:background="@android:color/holo_red_light" 
        android:minHeight="?attr/actionBarSize" 
        android:theme="?attr/actionBarTheme" 
        app:layout_constraintLeft_toLeftOf="parent" 
        app:layout_constraintTop_toTopOf="parent" 
        app:layout_constraintRight_toRightOf="parent" 
        app:layout_constraintBottom_toTopOf="@+id/main_listview"/> 
    
    <ListView 
        android:id="@+id/main_listview" 
        android:layout_width="wrap_content" 
        android:layout_height="0dp" 
        app:layout_constraintBottom_toBottomOf="parent" 
        app:layout_constraintLeft_toLeftOf="parent" 
        app:layout_constraintRight_toRightOf="parent" 
        app:layout_constraintTop_toBottomOf="@+id/toolbar"></ListView> 
    

    +0

    ListViewで上限制約を忘れてしまった –

    関連する問題