壁纸应用程序的安卓裁剪/缩放/平移库?类似于新星启动器"Set Wallpaper"屏幕



我一直在开发一个壁纸应用程序,它可以获取一些壁纸(通过我选择的api),为用户提供分享、直接设置为壁纸(如果支持可滚动)或编辑和设置图片的功能。

这个编辑界面是我遇到一些bug/问题的地方。

我需要用户能够裁剪/缩放/平移图像到他们的喜欢,并将其设置为壁纸。类似于Nova壁纸的做法,如果裁剪选择减少,整个图像就会相应地放大。我相信所有这些都发生在一个imageview中。

但是,在我的情况下,我碰巧使用两个imageview,一个用于裁剪,另一个用于缩放。裁剪库:github.com/edmodo/cropper/

一旦用户裁剪,第二个图像视图就会被从裁剪器中选择的位图填充。这个imageview用于缩放或平移。缩放/平移库:github.com/jasonpolites/gesture-imageview

这是该屏幕的布局:https://i.stack.imgur.com/wnjcP.jpg

和代码:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:gesture-image="http://schemas.polites.com/android"
android:id="@+id/scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout 
android:id="@+id/mylayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:orientation="vertical"
tools:context=".MainActivity" >
 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >
    <Button
        android:id="@+id/Button_crop"
        style="@style/RoboTheme"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="25dp"
        android:paddingRight="25dp"
        android:text="@string/crop"
        android:textColor="#33B5E5"
        android:textSize="12sp" />
    <ImageButton
        android:id="@+id/Button_rotate_left"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/rotate_left" />
    <ImageButton
        android:id="@+id/Button_rotate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/rotate_right" />
     <Button
        android:id="@+id/Button_setother"
        style="@style/RoboTheme"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="25dp"
        android:paddingRight="25dp"
        android:text="@string/setother"
        android:textColor="#33B5E5"
        android:textSize="12sp" />

</LinearLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" 
    android:id="@+id/checkboxlayout">
     <CheckBox
         android:id="@+id/scrollable"
         style="@style/RoboTheme"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:textColor="#33B5E5"
         android:textSize="12sp"
         android:checked="false"
         android:text="Scrollable" />

     <Button
        android:id="@+id/Button_setwallpaper"
        style="@style/RoboTheme"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="25dp"
        android:paddingRight="25dp"
        android:text="@string/setwallpaper"
        android:textColor="#33B5E5"
        android:textSize="12sp" />
 </LinearLayout>

 <com.edmodo.cropper.CropImageView
         xmlns:custom="http://schemas.android.com/apk/res-auto"
         android:id="@+id/CropImageView"
         android:layout_width="wrap_content"
         android:layout_height="0dp"
         android:layout_weight="1"
         android:layout_gravity="center"
         android:adjustViewBounds="true" />
<com.polites.android.GestureImageView
    android:id="@+id/croppedImageView"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:adjustViewBounds="true"
    android:contentDescription="@string/croppedImageDesc"
    gesture-image:max-scale="10.0"
    gesture-image:min-scale="0.1"
    gesture-image:strict="false" />
 </LinearLayout>
</ScrollView>

然而,我希望得到一些帮助,使这个布局有效。我不需要在不同的设备上滚动或基于类似于Nova Launcher的"设置壁纸"屏幕的东西,如:

https://i.stack.imgur.com/WaJRO.png

非常感谢任何帮助!

谢谢,

Arnab

Nova Launcher的裁剪活动是基于来自AOSP Gallery2 https://android.googlesource.com/platform/packages/apps/Gallery2/的CropImage.java。引入所有必需的依赖关系,然后修复针对SDK构建的所有构建问题(就像他们可能在视图中使用mLeft,而您必须用getLeft()替换它)需要一点工作。

最新更新