【问题标题】:tools:layout_editor_absoluteY not working工具:layout_editor_absoluteY 不工作
【发布时间】:2017-04-11 05:54:23
【问题描述】:

我尝试使用 android.support.constraint.ConstraintLayout 设计布局,从 android studio 我可以看到预览效果很好,但是当我在手机中构建并运行时,预览会一个接一个地显示我不想要的。

我的布局设计:

<?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>

【问题讨论】:

    标签: android android-layout android-studio


    【解决方案1】:

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

    【讨论】:

    • 比使用 ConstraintLayout 有什么好处。
    • 有很多好处,但是您没有使用ConstraintLayout 功能,您只是绝对定位视图并且它不起作用,因为这些绝对定位值仅适用于编辑器预览。例如,如果您希望它始终位于 videoView ImageView 下,则应在 TextView 年份使用 app:layout_constraintTop_toBottomOf=”@id/videoView”
    • 如果不影响最终布局,仅在编辑器预览中定位视图有什么好处?
    • 当动态计算最终视图位置时,有时它可以帮助您提示特定视图的定位方式。它仅用于模拟目的。
    • 有人可以添加一个这样的例子吗?从答案中不清楚解决方案是什么。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-05
    • 2017-06-16
    • 2014-02-22
    • 1970-01-01
    相关资源
    最近更新 更多