2017-05-14 32 views
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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.app.thestickermafia.tsm.TSMCatagory" 
    android:background="@drawable/bg"> 

    <ImageButton 
     android:id="@+id/A_F" 
     android:layout_width="240dp" 
     android:layout_height="240dp" 
     app:srcCompat="@drawable/green" 
     tools:layout_editor_absoluteX="50dp" 
     tools:layout_editor_absoluteY="88dp" /> 

    <ImageButton 
     android:id="@+id/G_M" 
     android:layout_width="240dp" 
     android:layout_height="240dp" 
     app:srcCompat="@drawable/green" 
     tools:layout_editor_absoluteX="330dp" 
     tools:layout_editor_absoluteY="88dp" /> 

    <ImageButton 
     android:id="@+id/N_S" 
     android:layout_width="240dp" 
     android:layout_height="240dp" 
     app:srcCompat="@drawable/green" 
     tools:layout_editor_absoluteX="50dp" 
     tools:layout_editor_absoluteY="351dp" /> 

    <ImageButton 
     android:id="@+id/T_Z" 
     android:layout_width="240dp" 
     android:layout_height="240dp" 
     app:srcCompat="@drawable/green" 
     tools:layout_editor_absoluteX="330dp" 
     tools:layout_editor_absoluteY="350dp" /> 

    <ImageButton 
     android:id="@+id/Font" 
     android:layout_width="521dp" 
     android:layout_height="200dp" 
     app:srcCompat="@drawable/orange" 
     tools:layout_editor_absoluteX="50dp" 
     tools:layout_editor_absoluteY="610dp" /> 

    <SearchView 
     android:id="@+id/search_viewr" 
     android:layout_width="520dp" 
     android:layout_height="49dp" 
     android:iconifiedByDefault="false" 
     android:queryHint="Search Ghrapics" 
     tools:layout_editor_absoluteX="50dp" 
     app:layout_constraintTop_toTopOf="parent" 
     android:layout_marginTop="25dp" /> 


</android.support.constraint.ConstraintLayout> 
+0

你試過另一種佈局了嗎?甚至嘗試改變佈局寬度? – Sarah

+0

向你的帖子添加屏幕截圖可以幫助我們解決你的問題。 –

回答

0

您需要在佈局中爲每個View添加約束條件。 tools:layout_editor_absoluteXtools:layout_editor_absoluteY值僅適用於設計視圖。看到這個reference

具體做法是:

當你把一個視圖到PCB編輯器,它會留在你離開它,即使它沒有限制。但是,這只是爲了使編輯更容易;如果在設備上運行佈局時視圖沒有約束,則它將在[0,0]位置(左上角)繪製。