Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android:如何将可滚动照片放入imageView?_Android_Xml_Imageview_Transform_Android Glide - Fatal编程技术网

android:如何将可滚动照片放入imageView?

android:如何将可滚动照片放入imageView?,android,xml,imageview,transform,android-glide,Android,Xml,Imageview,Transform,Android Glide,我现在正在做一个项目,实际上我想做的是给一个用户一个圆圈,当他点击它时,他将能够从gallery或使用他/她的cam选择照片,我已经绘制了我的自定义圆圈形状,然后使用Glide Transformation Library将图像放入其中,但问题是我无法在这个圆圈内滚动显示用户图像的某些特定部分。 任何解决方案都会有帮助。 我的XML文件如下所示: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:andro

我现在正在做一个项目,实际上我想做的是给一个用户一个圆圈,当他点击它时,他将能够从gallery或使用他/她的cam选择照片,我已经绘制了我的自定义圆圈形状,然后使用Glide Transformation Library将图像放入其中,但问题是我无法在这个圆圈内滚动显示用户图像的某些特定部分。 任何解决方案都会有帮助。 我的XML文件如下所示:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#D2DDD7"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.karim.helloworld.MainActivity">
<ImageView
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    android:id="@+id/imgView"
    android:padding="5dp"
    android:scaleType="centerCrop"
    android:background="@drawable/circle_image"/>
</RelativeLayout>

这里有一个
imageView
的滚动示例,希望对您有所帮助:

// set maximum scroll amount (based on center of image)
    int maxX = (int)((bitmapWidth / 2) - (screenWidth / 2));
    int maxY = (int)((bitmapHeight / 2) - (screenHeight / 2));
// set scroll limits
final int maxLeft = (maxX * -1);
final int maxRight = maxX;
final int maxTop = (maxY * -1);
final int maxBottom = maxY;

// set touchlistener
ImageView_BitmapView.setOnTouchListener(new View.OnTouchListener()
{
    float downX, downY;
    int totalX, totalY;
    int scrollByX, scrollByY;
    public boolean onTouch(View view, MotionEvent event)
    {
        float currentX, currentY;
        switch (event.getAction())
        {
            case MotionEvent.ACTION_DOWN:
                downX = event.getX();
                downY = event.getY();
                break;

            case MotionEvent.ACTION_MOVE:
                currentX = event.getX();
                currentY = event.getY();
                scrollByX = (int)(downX - currentX);
                scrollByY = (int)(downY - currentY);

                // scrolling to left side of image (pic moving to the right)
                if (currentX > downX)
                {
                    if (totalX == maxLeft)
                    {
                        scrollByX = 0;
                    }
                    if (totalX > maxLeft)
                    {
                        totalX = totalX + scrollByX;
                    }
                    if (totalX < maxLeft)
                    {
                        scrollByX = maxLeft - (totalX - scrollByX);
                        totalX = maxLeft;
                    }
                }

                // scrolling to right side of image (pic moving to the left)
                if (currentX < downX)
                {
                    if (totalX == maxRight)
                    {
                        scrollByX = 0;
                    }
                    if (totalX < maxRight)
                    {
                        totalX = totalX + scrollByX;
                    }
                    if (totalX > maxRight)
                    {
                        scrollByX = maxRight - (totalX - scrollByX);
                        totalX = maxRight;
                    }
                }

                // scrolling to top of image (pic moving to the bottom)
                if (currentY > downY)
                {
                    if (totalY == maxTop)
                    {
                        scrollByY = 0;
                    }
                    if (totalY > maxTop)
                    {
                        totalY = totalY + scrollByY;
                    }
                    if (totalY < maxTop)
                    {
                        scrollByY = maxTop - (totalY - scrollByY);
                        totalY = maxTop;
                    }
                }

                // scrolling to bottom of image (pic moving to the top)
                if (currentY < downY)
                {
                    if (totalY == maxBottom)
                    {
                        scrollByY = 0;
                    }
                    if (totalY < maxBottom)
                    {
                        totalY = totalY + scrollByY;
                    }
                    if (totalY > maxBottom)
                    {
                        scrollByY = maxBottom - (totalY - scrollByY);
                        totalY = maxBottom;
                    }
                }

                ImageView_BitmapView.scrollBy(scrollByX, scrollByY);
                downX = currentX;
                downY = currentY;
                break;

        }

        return true;
    }
});
//设置最大滚动量(基于图像中心)
intmaxx=(int)((位图宽度/2)-(屏幕宽度/2));
intmaxy=(int)((位图高度/2)-(屏幕高度/2));
//设置滚动限制
最终整数maxLeft=(maxX*-1);
最终整数maxRight=maxX;
最终整数maxTop=(maxY*-1);
最终整数maxBottom=maxY;
//设置touchlistener
ImageView\u BitmapView.setOnTouchListener(新视图.OnTouchListener()
{
飘落,飘落;
整数totalX,totalY;
int scrollByX,scrollByY;
公共布尔onTouch(视图、运动事件)
{
浮动电流x,电流y;
开关(event.getAction())
{
case MotionEvent.ACTION\u DOWN:
downX=event.getX();
downY=event.getY();
打破
case MotionEvent.ACTION\u移动:
currentX=event.getX();
currentY=event.getY();
scrollByX=(int)(downX-currentX);
scrollByY=(int)(downY-currentY);
//滚动至图像左侧(图片向右移动)
如果(当前X>向下X)
{
如果(totalX==maxLeft)
{
scrollByX=0;
}
如果(totalX>maxLeft)
{
totalX=totalX+scrollByX;
}
如果(totalXmaxRight)
{
scrollByX=maxRight-(totalX-scrollByX);
totalX=maxRight;
}
}
//滚动至图像顶部(图片移动至底部)
如果(当前Y>绒毛)
{
如果(总计==maxTop)
{
scrollby=0;
}
如果(总计>最大值)
{
totalY=totalY+scrollby;
}
如果(总计<最大值)
{
scrollByY=maxTop-(总计-scrollByY);
总Y=最大上限;
}
}
//滚动至图像底部(图片移动至顶部)
如果(当前Y<向下)
{
如果(总计==maxBottom)
{
scrollby=0;
}
如果(总<最大底部)
{
totalY=totalY+scrollby;
}
如果(总体>最大底部)
{
scrollByY=maxBottom-(总计-scrollByY);
总Y=最大底部;
}
}
ImageView\u BitmapView.scrollBy(scrollByX,scrollByY);
downX=电流x;
绒毛=电流;
打破
}
返回true;
}
});
编辑:使用以下XML创建掩码:

<FrameLayout>
    <ImageView />  put a image which has a transparent circle in it
    <ImageView />  your image 
</FrameLayout>

放置一个有透明圆圈的图像
你的形象

Hmmmmm,回答得好,这有助于我使图像可滚动,但实际上它不符合我的想象,我想在圆圈内滚动?你有什么建议吗??谢谢@LychmanITYeah,我想你应该给你的圈子做个面具。我不明白,你的意思是我应该用框架布局替换我的相对布局。。如果是这样,您的意思是,在第一个imageView中,我应该将imageView与background@drawble/myshape.xml放在一起,而在第二个imageView中,我应该将imageView与src:../image???放在一起??请参考那个链接,了解我所说的滚动圈外的意思:阅读这一条:是的,非常感谢,它很有效(Y)。检查此项:最后一个问题是:您是否知道如何删除圆圈外图像的剩余部分,并让用户仅滚动到图像中??谢谢你的努力@LychmanIT
<FrameLayout>
    <ImageView />  put a image which has a transparent circle in it
    <ImageView />  your image 
</FrameLayout>