2017-08-16 7 views
0

複雑なレイアウトを含むConstraintLayoutを作成しようとしていますが、何らかの理由で期待通りに表示されません。制約を修正して予期される結果を達成するためには、何をしなければならないか誰にでも分かっていますか?ConstraintLayoutで適切に制約されていない項目

XMLレイアウトコード

<?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="wrap_content" 
    android:orientation="vertical" 
    android:background="@color/lightgrey" 
    android:weightSum="100"> 

    <com.google.android.gms.maps.MapView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/mymap" 
     android:name="com.google.android.gms.maps.SupportMapFragment" 
     app:layout_constraintBottom_toTopOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     tools:layout_constraintLeft_creator="1" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     android:layout_width="41dp" 
     android:layout_height="0dp" 
     tools:layout_editor_absoluteY="0dp" 
     tools:layout_editor_absoluteX="8dp" /> 

    <android.support.constraint.Guideline 
     android:id="@+id/guideline" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     app:layout_constraintGuide_percent="0.9"/> 

    <ImageView 
     android:id="@+id/imageViewSun" 
     android:importantForAccessibility="no" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/ic_sun_black" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintBottom_toBottomOf="guideline" 
     app:layout_constraintRight_toLeftOf="@+id/switch_stationstopmap_lighttheme" 
     app:layout_constraintHorizontal_bias="0.5" 
     android:layout_marginEnd="8dp" 
     android:layout_marginBottom="0dp" /> 

    <Switch 
     android:id="@+id/switch_stationstopmap_lighttheme" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintBottom_toTopOf="@+id/guideline" 
     app:layout_constraintHorizontal_bias="0.5" 
     android:background="@android:color/transparent" 
     android:theme="@android:style/Theme.Material.Light" /> 

    <ImageView 
     android:id="@+id/imageViewMoon" 
     android:importantForAccessibility="no" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/ic_moon_black" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintHorizontal_bias="0.508" 
     app:layout_constraintLeft_toRightOf="@+id/switch_stationstopmap_lighttheme" 
     android:layout_marginStart="8dp" 
     android:layout_marginEnd="8dp" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintBottom_toTopOf="@+id/guideline" 
     android:layout_marginBottom="5dp" /> 
</android.support.constraint.ConstraintLayout> 

期待される結果

enter image description here

現在の結果

enter image description here

MapView高さは、3つの項目の下の高さ

  • レイアウトの高さの90%であることが必要である所望の要求

    enter image description here

    1. レイアウトの高さの10%であることが必要
    2. Switchは画面の真ん中にある必要があります
    3. 3つのアイテム(画像ビューとスイッチの両方)は、ポイント2の10%の高さの垂直中心に正確にくる必要があります。
    4. 太陽のImageViewは、画面の左側とスイッチ
    5. 月のImageViewはちょうど中間水平スイッチと、画面の右側の間
    6. 5DPマージンの下で10%の高さの頂部および底部の両方に必要とされることが必要ですレイアウト(3つのアイテムの場合)
    7. 上記のすべてがの結果になるはずです画像、私が望むものです。
  • +0

    一つ 'アプリです:layout_constraintBottom_toTopOf =「親」は、'マップに適用されます。これは地図を消してしまっているようです。 –

    答えて

    1

    これを試すことができます。ルートレイアウトの高さをandroid:layout_height="match_parent"に変更したところ、ほとんどの問題は解決されました。私はあなたのレイアウトで見る奇妙なの

    <?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" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:background="@color/colorAccent"> 
        <com.google.android.gms.maps.MapView 
         xmlns:android="http://schemas.android.com/apk/res/android" 
         android:id="@+id/mymap" 
         android:name="com.google.android.gms.maps.SupportMapFragment" 
         android:layout_width="0dp" 
         android:layout_height="0dp" 
         android:background="#f00" 
         app:layout_constraintBottom_toBottomOf="@+id/guideline" 
         app:layout_constraintLeft_toLeftOf="parent" 
         app:layout_constraintRight_toRightOf="parent" 
         app:layout_constraintTop_toTopOf="parent"/> 
    
        <ImageView 
         android:id="@+id/imageViewSun" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:src="@drawable/ic_action_name" 
         app:layout_constraintBottom_toBottomOf="parent" 
         app:layout_constraintLeft_toLeftOf="parent" 
         app:layout_constraintRight_toLeftOf="@+id/switch_stationstopmap_lighttheme" 
         app:layout_constraintTop_toBottomOf="@+id/guideline" 
         /> 
    
        <Switch 
         android:id="@+id/switch_stationstopmap_lighttheme" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center_horizontal" 
         android:background="@android:color/transparent" 
         android:theme="@android:style/Theme.Material.Light" 
         app:layout_constraintBottom_toBottomOf="parent" 
         app:layout_constraintLeft_toRightOf="@+id/imageViewSun" 
         app:layout_constraintRight_toLeftOf="@+id/imageViewMoon" 
         app:layout_constraintTop_toBottomOf="@+id/guideline"/> 
    
        <ImageView 
         android:id="@+id/imageViewMoon" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:src="@drawable/ic_action_name" 
         app:layout_constraintBottom_toBottomOf="parent" 
         app:layout_constraintLeft_toRightOf="@+id/switch_stationstopmap_lighttheme" 
         app:layout_constraintRight_toRightOf="parent" 
         app:layout_constraintTop_toBottomOf="@+id/guideline"/> 
    
        <android.support.constraint.Guideline 
         android:id="@+id/guideline" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:orientation="horizontal" 
         app:layout_constraintGuide_percent="0.9"/> 
    </android.support.constraint.ConstraintLayout> 
    
    関連する問題