2017-07-27 5 views
0

私は、ConstraintLayoutを使用して私のアプリケーションのGUIを作ろうとしていましたが、ボタンのように動作するイメージを持っていますが、これらのボタン(または実際には何か)は、 (そして保存する)場合、ちょうど数(この場合は16)に戻ります。ConstraintLayout Editor Biased

私はここで間違っていますか?これを引き起こす原因/エディタが位置をリセットするのはなぜですか?

http://i.imgur.com/OFndFb7.gifv(GIF - 40代)

バージョン:Android用

  • ConstraintLayout - V 1.0.2
  • アンドロイドスタジオ - 2.3.3#AI-162.4069837

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="match_parent" 
    tools:layout_editor_absoluteY="25dp" 
    tools:layout_editor_absoluteX="0dp"> 

    <Button 
     android:id="@+id/Button_Color_Red" 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:layout_marginTop="80dp" 
     android:layout_marginStart="16dp" 
     android:background="@drawable/btn_red_color_menu" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintLeft_toLeftOf="parent" /> 

    <Button 
     android:id="@+id/Button_Color_Indigo" 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:layout_marginTop="80dp" 
     android:layout_marginStart="8dp" 
     android:background="@drawable/btn_indigo_color_menu" 
     app:layout_constraintLeft_toRightOf="@+id/Button_Color_Yellow" 
     app:layout_constraintTop_toTopOf="parent" /> 

    <Button 
     android:id="@+id/Button_Color_Green" 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:layout_marginTop="80dp" 
     android:layout_marginStart="8dp" 
     android:background="@drawable/btn_green_color_menu" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintLeft_toRightOf="@+id/Button_Color_Indigo"/> 

    <Button 
     android:id="@+id/Button_Color_Yellow" 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:layout_marginTop="80dp" 
     android:layout_marginStart="8dp" 
     android:background="@drawable/btn_yellow_color_menu" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintLeft_toRightOf="@+id/Button_Color_Red" /> 

</android.support.constraint.ConstraintLayout> 
012 btn_x_color_menuため

XML:

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
     <shape android:shape="rectangle"> 
      <solid android:color="@color/Red_Primary"/> 
     </shape> 
    </item> 
</selector> 
+0

XMLを見ると、マージンも16dpに戻っていますか? –

+0

うん、アンドロイド:layout_marginStart = "16dp" ' – Fabricio20

+0

Hm。私は困惑しています...私はデザインタブを使用しないので、私はその癖に精通し​​ていません。 –

答えて

2

競合しているボタンButton_Color_Green上の2つの属性があります。あなたがボタンを移動すると

android:layout_marginLeft="16dp" 
    android:layout_marginStart="8dp" 

デザイナーがandroid:layout_marginLeftを作成しますが、android:layout_marginStartは変わらないとの紛争に残っています。そのため、ウィジェットを移動した後にマージンが戻ってしまうのです。

左から右のレイアウトでは、これらの2つの属性は同じである必要がありますが、デザイナーはandroid:layout_marginLeftを変更したいと思われるが、存在する場合はandroid:layout_marginStartとします。

これはConstraintLayout 1.0.2のバグである可能性があります。修正またはそれ以上の解決策が見つかるまで、これらの属性を手動で変更して同じものにするか、android:layout_marginLeftを使用して、あとでandroid:layout_marginStartを手動で追加してください。 (Lintはあなたにこのことを思い出させるべきです)

これで問題を知ったので、より良い解決策を試すことができます。

こちらがお役に立てば幸いです。

+1

良いキャッチ。 API 17+をターゲットにできる場合は、 'android:layout_marginStart'と書いて、アンドロイド:layout_marginLeftをドロップしてください。 – ephemient