Reputation: 1
I am a Android developer from China(My English sucks...).
I want to make effect like figure 1: A FrameLayouts width and height is both 50% of the screen width,contains an ImageView. The ImageView
s width and height is both 50% of the FrameLayout.
I have made it by using PercentLayout,but I want to use constraintLayout to achieve the same effect.How should I do?
Upvotes: 0
Views: 221
Reputation: 1051
Try this:
<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>
Upvotes: 0