2017-04-11 651 views
2

我嘗試從android studio中使用android.support.constraint.ConstraintLayout設計佈局我可以看到預覽效果很好,但是當我在電話中構建並運行時,預覽會一個接一個地顯示出我永遠不想要。工具:layout_editor_absoluteY不工作

我的佈局設計: enter image description here

<?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" 
    android:background="@color/black" 
    tools:context="co.gakkmedia.videoapps.DetailsViewActivity"> 


    <ImageView 
     android:id="@+id/videoView" 
     android:layout_width="wrap_content" 
     android:layout_height="200dp" 
     tools:layout_editor_absoluteY="0dp" 
     tools:layout_editor_absoluteX="0dp" 
     android:src="@drawable/video_preview_01" 
     /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Arraw" 
     android:textSize="20dp" 
     tools:layout_editor_absoluteY="166dp" 
     tools:layout_editor_absoluteX="0dp" 

     android:textColor="@color/white" 

     /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="09.45.05" 
     tools:layout_editor_absoluteY="166dp" 
     tools:layout_editor_absoluteX="291dp" 

     android:textSize="20dp" 
     android:textColor="@color/white" 
     /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="2016" 
     tools:layout_editor_absoluteY="200dp" 
     tools:layout_editor_absoluteX="0dp" 

     android:textSize="20dp" 
     android:textColor="@color/white" 
     /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="5 sections" 
     tools:layout_editor_absoluteY="200dp" 
     tools:layout_editor_absoluteX="101dp" 

     android:textSize="20dp" 
     android:textColor="@color/white" 
     /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Add to MyPlaylist" 
     tools:layout_editor_absoluteY="243dp" 
     tools:layout_editor_absoluteX="112dp" 

     android:textSize="20dp" 
     android:textColor="@color/white" 
     /> 

</android.support.constraint.ConstraintLayout> 

回答

5

layout_editor屬性僅用於編輯預覽和對最終的佈局沒有影響。您應該使用ConstraintLayout特定屬性來定位元素。

+0

比使用ConstraintLayout有什麼好處。 – Tariqul

+2

雖然有很多好處,但是您沒有使用'ConstraintLayout'功能,您只是完全擺放視圖,並且它不起作用,因爲這些絕對定位值僅適用於編輯器預覽。例如,如果您希望它始終位於_videoView_「ImageView」下,則應在年份「TextView」上使用'app:layout_constraintTop_toBottomOf =「@ id/videoView」'' –