2017-07-15 81 views
0

我是Android編程新手,並開始使用Android Studio開發一個非常簡單的應用程序。但是,使用XML文件中的「設計」視圖,部件未正確放置。Android小部件位置不正確

查看圖像 - 有兩個小部件 - Button和TextView。它們位於「設計」視圖的不同位置,但它們顯示在模擬器的左上角。

這是怎麼發生的? UI snapshot

回答

1

你的按鈕視圖是使用工具的屬性,是不是在裝置中,只有預覽工作一定要刪除它們,並使用相應的屬性

<?xml version="1.0" encoding="utf-8"?> 
 
<android.support.constraint.ConstraintLayout 
 
    xmlns:android="http://schemas.android.com/apk/res/android" 
 
    xmlns:tools="http://schemas.android.com/tools" 
 
    android:layout_width="match_parent" 
 
    android:layout_height="match_parent" 
 
    xmlns:app="http://schemas.android.com/apk/res-auto"> 
 

 
    <TextView 
 
     android:id="@+id/tv" 
 
     android:text="adhfbkj" 
 
     android:layout_width="wrap_content" 
 
     android:layout_height="wrap_content" 
 
     app:layout_constraintBottom_toBottomOf="parent" 
 
     app:layout_constraintTop_toTopOf="parent" 
 
     app:layout_constraintStart_toStartOf="parent" 
 
     app:layout_constraintEnd_toEndOf="parent"/> 
 

 
    <Button 
 
     android:text="button" 
 
     android:layout_width="wrap_content" 
 
     android:layout_height="wrap_content" 
 
     app:layout_constraintTop_toBottomOf="@+id/tv" 
 
     app:layout_constraintStart_toStartOf="parent" 
 
     app:layout_constraintEnd_toEndOf="parent"/> 
 

 
</android.support.constraint.ConstraintLayout>

+0

如何將我的位置按鈕到屏幕上的自定義位置,未連接到「電視」TextView? –

+0

如果您可以將您的按鈕相對於父母或其他視圖定位,如果您添加任何 –

+0

您可以在這裏進一步閱讀https://medium.com/@loutry/guide-to-constraintlayout-407cd87bc013 –