tools:layout_editor_absoluteY属性无法正常工作

5
我尝试使用android.support.constraint.ConstraintLayout设计布局,在Android Studio中我可以看到预览效果很好,但是当我在手机上构建和运行时,预览效果会一个接一个地显示,这不是我想要的。
我的布局设计如下图所示: 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>
1个回答

12

layout_editor 属性仅用于编辑器预览,并不影响最终布局。您应该使用 ConstraintLayout 特定的属性来定位元素。


使用ConstraintLayout的好处是什么? - Md Tariqul Islam
4
虽然有很多好处,但你没有使用ConstraintLayout的功能,而是直接对视图进行绝对定位,这样不起作用,因为那些绝对定位值只适用于编辑器预览。例如,如果你想让年份TextView始终位于_videoView_ ImageView下方,应该在其上使用app:layout_constraintTop_toBottomOf="@id/videoView" - Juan Martinez
如果在编辑器预览中定位视图不影响最终布局,那么这样做的好处是什么? - Self Dot
1
有时候,当最终视图位置是动态计算的时候,它可以为您提供某个视图将被定位的提示,这可能是有用的。它仅用于模拟目的。 - Juan Martinez
有人可以添加一个带有这样一个示例的行吗?从答案中不清楚解决方案是什么。 - CognizantApe

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接