【问题标题】:Can ConstraintLayout perform the same effect like PercentLayout?ConstraintLayout 可以像 PercentLayout 一样实现效果吗?
【发布时间】:2018-02-27 20:14:27
【问题描述】:

我是来自中国的 Android 开发人员(我的英语很烂...)。 我想让效果如图 1:FrameLayouts width and height is both 50% of the screen width,contains an ImageView. The ImageViews 的宽度和高度都是 FrameLayout 的 50%。 我用PercentLayout做到了,但是我想用constraintLayout来达到同样的效果,我该怎么办?

【问题讨论】:

标签: java android android-constraintlayout android-percent-library


【解决方案1】:

试试这个:

<android.support.constraint.ConstraintLayout 
android:layout_width="match_parent"
android:layout_height="match_parent">

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

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

<ImageView
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:scaleType="centerCrop"
    android:src="@drawable/wall"
    android:layout_gravity="center"
    app:layout_widthPercent="50%"
    app:layout_constraintDimensionRatio="1:1"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintLeft_toRighttOf="@+id/leftGuideline"
    app:layout_constraintRight_toLeftOf="@+id/rightGuideline"
    app:layout_constraintBottom_toBottomOf="parent" />

</android.support.constraint.ConstraintLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-26
    • 2010-09-22
    • 1970-01-01
    • 2011-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多