2017-03-10 73 views
1

我只能找到一條與此相關的線程,而答案並沒有幫助修復錯誤。我在新的筆記本電腦上使用全新安裝的Android Studio(如果有需要的話)(也許我需要安裝目前不存在的東西)。Java中的約束錯誤Android Studio

錯誤:這種觀點是沒有限制的,它只有設計時的位置,所以它會跳轉到(0,0),除非你添加約束

EDIT2:看來Android Studio中的新版本沒有按不使用相對佈局?我嘗試過按照這個線程手動更改代碼(How to switch from the default ConstraintLayout to RelativeLayout in Android Studio 2.3.3)。還是行不通。

編輯: 這是從以前的項目中的代碼示例(你可以看到,這是不同的,從我的實際電流代碼):

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/activity_main" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context="com.example.squirreloverlord.ccarringtonphonephotoprint.MainActivity"> 

下面是我的主要活動代碼給我上面的錯誤x4(button/textView x2/radiogroup)。

<?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.mercenaryferret.ccarrington1_currency.MainActivity"> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/app_title" 
    android:textSize="24sp" 
    android:textStyle="bold|italic" 
    app:layout_constraintBottom_toBottomOf="parent" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toTopOf="parent" 
    app:layout_constraintVertical_bias="0.032" /> 

<EditText 
    android:id="@+id/editText_usd" 
    android:layout_width="350dp" 
    android:layout_height="wrap_content" 
    android:ems="10" 
    android:hint="@string/us_label" 
    android:inputType="numberDecimal" 
    android:textAlignment="center" 
    android:textSize="12sp" 
    tools:layout_editor_absoluteX="17dp" 
    tools:layout_editor_absoluteY="69dp" 
    /> 

<RadioGroup 
    android:id="@+id/radioGrp" 
    android:layout_width="213dp" 
    android:layout_height="100dp" 
    tools:layout_editor_absoluteX="86dp" 
    tools:layout_editor_absoluteY="122dp" 
    > 

    <RadioButton 
     android:id="@+id/radioButtonEuro" 
     android:layout_width="98dp" 
     android:layout_height="wrap_content" 
     android:text="@string/euro_label" 
     tools:layout_editor_absoluteX="110dp" 
     tools:layout_editor_absoluteY="203dp" /> 

    <RadioButton 
     android:id="@+id/radioButtonCanada" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/canada_label" /> 

    <RadioButton 
     android:id="@+id/radioButtonMexico" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/mex_label" /> 
</RadioGroup> 

<Button 
    android:id="@+id/buttonConvert" 
    android:layout_width="368dp" 
    android:layout_height="wrap_content" 
    android:text="@string/convert_label" 
    android:textAlignment="center" 
    tools:layout_editor_absoluteX="8dp" 
    tools:layout_editor_absoluteY="248dp" /> 

<TextView 
    android:id="@+id/textViewResults" 
    android:layout_width="316dp" 
    android:layout_height="31dp" 
    tools:layout_editor_absoluteX="34dp" 
    tools:layout_editor_absoluteY="354dp" 
    /> 

預先感謝您。

回答

0

你需要添加一些缺少的約束,這裏是如何做到這一點。

  1. 轉到設計視圖
  2. 右鍵點擊你的widget
  3. 點擊 「約束佈局」
  4. 點擊 「推斷約束」

如果上述方法無效,請嘗試以下。

  1. 轉到設計視圖
  2. 右鍵點擊你的widget
  3. 清除所有約束
  4. 點擊 「約束佈局」
  5. 點擊 「推斷約束」
0

首先在組件樹上有ConstraintLayout left點擊它並彈出列表打開,然後按照下列步驟操作: -

  1. 約束佈局>>清楚所有的約束然後
  2. 約束佈局>>添加推斷約束