使用ConstraintLayout进行绝对定位

我正在尝试使旧的应用程序重新焕发活力。我使用图书馆在平面图上定位商店的位置,但似乎已弃用。

我对ConstraintLayout的尝试: 我在编辑器中放置了所有项目,然后按“推论约束”按钮,如在StackOverflow上建议的那样。效果很好...直到我在设备上运行我的应用程序,并注意到所有poi遍布整个地方。

有一个不赞成使用的视图,该视图支持layout_marginLeftPercent等,但是我似乎找不到ConstraintLayout替代方法吗?有什么建议吗?

g109007 回答:使用ConstraintLayout进行绝对定位

您可以使用百分比来定义宽度和高度。

Less

这会将宽度定义为屏幕宽度的40%。结合使用此百分比和准则,您可以创建所需的任何基于百分比的布局。

,

这可以通过使用ConstraintLayout使用Guidelines来完成。因此,如果您希望将点放置在屏幕顶部的24%位置,而将其放置在屏幕的左侧14%,则代码可能看起来像这样:

<android.support.constraint.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.constraint.Guideline
        android:id="@+id/guideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.14" />

    <android.support.constraint.Guideline
        android:id="@+id/guideline2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.24" />

    <ImageView
        android:id="@+id/dot"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toTopOf="@+id/guideline2"
        app:layout_constraintEnd_toStartOf="@+id/guideline"
        app:layout_constraintStart_toStartOf="@+id/guideline"
        app:layout_constraintTop_toTopOf="@+id/guideline2"
        app:srcCompat="@android:color/background_dark" />
</android.support.constraint.ConstraintLayout>

有关此问题的更多文档和信息,请参见here

本文链接:https://www.f2er.com/3110743.html

大家都在问