Может ли ConstraintLayout выполнять тот же эффект, что и PercentLayout?
Я разработчик Android из Китая (мой английский отстой...). Я хочу сделать эффект, как показано на рисунке 1: FrameLayouts width and height is both 50% of the screen width,contains an ImageView. The ImageView
Ширина и высота s составляют 50% от FrameLayout. Я сделал это с помощью PercentLayout, но я хочу использовать constraintLayout для достижения того же эффекта. Как мне это сделать?
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>