【问题标题】:How to scale buttons positions according to scaling background imageView?如何根据缩放背景图像视图缩放按钮位置?
【发布时间】:2018-09-04 17:30:47
【问题描述】:

imageView 顶部按钮位置的同步存在问题 - 当图像拉伸按钮保持在原位时。我希望按钮根据 imageView 缩放同步移动(同时保持纵横比)。

在附加的图片上,您可能会看到问题。当我通过手势调整图像大小时,按钮(图标 [V])保持其位置。我想在图像调整大小和拖动时自动移动按钮。

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/floorPlanLayout"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".OrderActivity">

    <com.github.chrisbanes.photoview.PhotoView
        android:id="@+id/imageViewFloorPlan"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/ic_placeholder"
        />

    <android.support.constraint.ConstraintLayout
        android:id="@+id/buttonsLayout"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:background="@drawable/imageview_border_background">

    </android.support.constraint.ConstraintLayout>

</android.support.constraint.ConstraintLayout>

【问题讨论】:

  • 这很难帮助你,因为我无法理解你想要什么。您能否添加您想要的结果的图像。不仅对我,对其他人来说,这都会变得容易得多。
  • 我尽量解释清楚。请参阅附图 - 标记为 [V] 的图标(即按钮)在调整图像大小时保持其位置,但我希望按钮将根据图像大小移动到新位置。
  • 似乎这样可以提供帮助:stackoverflow.com/questions/10013906/…。将Image设置为RelativeLayout的背景,并将Icons放入布局中。
  • 非常感谢!你节省了我的时间!

标签: android android-layout


【解决方案1】:

在我的情况下,使用带背景的布局比使用 imageview 更好(感谢 Daksh Agrawal)。当我查看有关提议的解决方案 (Android - zoom in/out RelativeLayout with spread/pinch) 的更多信息时,我发现它对我来说不太灵活。经过一番搜索,我发现:https://github.com/natario1/ZoomLayout。它的几个实用程序有助于非常轻松地缩放和平移 Layout 和 imageView。希望它可以帮助某人。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-28
    • 1970-01-01
    • 2011-02-19
    • 2011-12-29
    • 2012-09-24
    • 2012-07-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多