【问题标题】:Simple Android Layout Issue - Pinch image effect to work beyond its layout?简单的 Android 布局问题 - 捏图像效果以超出其布局?
【发布时间】:2017-10-26 00:52:19
【问题描述】:

我想使用捏合效果来放大和缩小图像。我可以缩小图像(即使图像在框架内变小)但我无法放大(即扩展框架可能是通过编程方式?

android 上的新手,所以对布局没有那么透彻的了解。 我使用了 github 库 Zoomage 但是我不太确定如何扩展图像帧以使其超出范围并进一步缩放..

我正在尝试做的可以在这里直观地看到

this image shows what i want to do, the red arrows represent the area outside frame where i'd like to zoom to, while black border in the layout itself

https://www.dropbox.com/s/qen6cqs3u0cq2n1/demo.mov?dl=0

<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
.......some other layouts here
  <LinearLayout android:layout_width="378dp"
    android:layout_height="341dp"
    android:orientation="vertical"
    android:padding="16dp"
    tools:layout_editor_absoluteY="107dp"
    tools:layout_editor_absoluteX="-4dp">

    <com.jsibbold.zoomage.ZoomageView
        android:id="@+id/songImage"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginRight="1dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginStart="8dp"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:zoomage_animateOnReset="true"
        app:zoomage_autoCenter="true"
        app:zoomage_autoResetMode="UNDER"
        app:zoomage_maxScale="8"
        app:zoomage_minScale="0.6"
        app:zoomage_restrictBounds="false"
        app:zoomage_translatable="true"
        app:zoomage_zoomable="true"
        tools:layout_editor_absoluteY="93dp" />
</LinearLayout>

</android.support.constraint.ConstraintLayout>

【问题讨论】:

    标签: android android-layout android-xml android-constraintlayout


    【解决方案1】:

    我没有使用过 Zoomage 库,但 AFAIK TouchImageView 是我用过的最好的库。

    你可以做的是:

    使用以下代码创建一个 TouchImageView.class 文件。

    Download the TouchImageView.class From here

    您在布局中的 ImageView 为:

     <com.example.YourApp.TouchImageView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/iv_touchImageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="4dp"
        android:scaleType="centerCrop" />
    

    在 Activity 中初始化 ImageView 时,请执行以下操作::

    TouchImageView selectedImage =findViewById(R.id.iv_touchImageView);
    selectedImage.setImageBitmap(yourBitmap);
    

    【讨论】:

    • 这看起来很不错,让我试试,我可以将缩放扩展到布局大小之外吗?因为这就是我想要做的?捏缩放功能是通过缩放添加的,但唯一的麻烦是布局......它就像没有超出布局大小?让我试试你的解决方案,谢谢!如果这解决了问题,将很快再次发送消息。再次,主要问题是在放大时超出了布局,就像在共享的视频中一样。我认为它与布局有关而不是与图书馆有关?
    • 好吧,如果您的意思是在放大图像时扩展布局,那么上述解决方案将无济于事。但是 TouchImageView 库可以帮助您在布局本身内放大和缩小。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多