2017-08-20 75 views
0

左側按鈕的邊距不斷變化,您可以在視頻中看到,我希望它們不會發生變化。約束佈局邊距不斷變化

我正在做一個計算器,我想移動所有的按鈕,而不改變邊距。

視頻是存在的:https://youtu.be/UT3zINpaMhY

下面是代碼:

<?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:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.a3ibm.calculator.MainActivity"> 


    <Button 
     android:id="@+id/button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Button" 
     app:layout_constraintBaseline_toBaselineOf="@+id/button2" 
     app:layout_constraintRight_toLeftOf="@+id/button2" 
     android:layout_marginRight="86dp" /> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Button" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintHorizontal_bias="0.864" 
     app:layout_constraintVertical_bias="0.319" /> 
</android.support.constraint.ConstraintLayout> 
+1

不清楚你在問什麼,請澄清你的問題。這種佈局的目的是什麼?你使用'ConstraintLayout'來達到什麼效果? – Blasanka

+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:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 


    <Button 
     android:id="@+id/button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Button" 
     app:layout_constraintEnd_toStartOf="@+id/button2" 
     android:layout_marginEnd="56dp" 
     android:layout_marginRight="56dp" 
     app:layout_constraintTop_toTopOf="@+id/button2" 
     app:layout_constraintBottom_toBottomOf="@+id/button2" 
     app:layout_constraintVertical_bias="0.0" /> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Button" 
     tools:layout_editor_absoluteY="186dp" 
     tools:layout_editor_absoluteX="208dp" /> 
</android.support.constraint.ConstraintLayout> 
+0

順便花花公子。如果你想讓按鈕水平移動,你應該垂直居中所有按鈕(通過選擇)。希望它是你想要的 –

+0

嘿人,如果它是你想要的請接受)) –

+0

其實我希望自由地移動按鈕,如視頻所示,但不改變邊距。 任何想法如何做到這一點? –