将视图移出约束布局

ale*_*sov 1 xml android android-constraintlayout

我要剪裁的图像

我想移动我的位置,ImageView这样它会距离ConstraintLayout(父对象)一半。LinearLayout

我所拥有的是图像,应该按照图片上的说明进行裁剪,因此图像的仅按钮侧应显示在实际设备上。其他部分应切除。

这是我的布局的一部分。

<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="wrap_content"
    android:orientation="vertical">

    <ImageView
        android:layout_width="71dp"
        android:layout_height="71dp"
        android:src="@drawable/someImage"
        app:layout_constraintTop_toTopOf="parent"/>

</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

那么,有什么好办法吗?

ale*_*sov 6

所以我找到了解决方案。基本上,您需要从容器中翻译出图像。

android:translationY="-22dp"
Run Code Online (Sandbox Code Playgroud)


Xen*_*ion 5

添加一条指导线并说明您的 ImageView 应该高于该指导线,例如此代码将使所有内容看起来都像您的布局:

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

   <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:src="@drawable/your_image"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintBottom_toBottomOf="@id/guideline" />

    <android.support.constraint.Guideline
        android:id="@+id/guideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_begin="163dp" />

</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)