2016-09-01 3 views
0

저는 현재 일부 프로젝트를 진행하고 있습니다. 실제로 원하는 것은 사용자에게 서클을 제공하고 클릭 할 때 갤러리 또는 카메라에서 사진을 선택할 수있게됩니다. 글라이드 변환 라이브러리 (Glide-Transformation Library)를 사용하여 실제로 원의 내 사용자 정의 모양을 그린 다음 이미지를 배치합니다. 그러나 문제는이 원 안쪽을 스크롤하여 사용자 이미지의 특정 부분을 표시 할 수 없다는 것입니다. 어떤 해결책이 도움이 될 것입니다. 내 XML 파일은 다음과 같다 :android : 스크롤 가능한 사진을 imageView에 배치하는 방법은 무엇입니까?

<?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> 

및 내 수업 활동은 다음과 같습니다

package com.example.karim.helloworld; 

import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.widget.ImageView; 

import com.bumptech.glide.Glide; 

import jp.wasabeef.glide.transformations.BlurTransformation; 
import jp.wasabeef.glide.transformations.CropCircleTransformation; 

public class MainActivity extends AppCompatActivity { 
    ImageView imageView; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     imageView = (ImageView) findViewById(R.id.imgView); 
     Glide.with(this).load(R.drawable.pk).bitmapTransform(new CropCircleTransformation(getApplicationContext())) 
       .into(imageView); 
    } 
}] 

custom shape & image view Image I want to scroll into it

답변

1

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; 
    } 
}); 

편집 : 다음과 XML을 사용하여 마스크를 확인하십시오

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

Hmmmmm는 대답 좋은,이 날 내 이미지를 스크롤 가능하게하는 데 도움이 있지만, 그것은 실제로 내가 상상하는 것을하지 않고, 내가 원 안에 스크롤하려면? 의견이 있으십니까 ?? 감사합니다. @LychmanIT –

+0

네, 당신은 당신의 서클을 가려 야한다고 생각합니다. http://stackoverflow.com/questions/14801075/android-how-to-apply-mask-on-imageview – LychmanIT

+0

내 편집을 확인하십시오. 이것은 도움이 될 것입니다 – LychmanIT

관련 문제