-1

내 Register 클래스에서 원형 이미지보기를 만들려고합니다. 나는 많은 솔루션을 시도했지만 솔루션 중 어느 것도 나를 위해 일하지 않았습니다. 누군가가 문제를 이해하도록 도와 줄 수 있습니까? 감사.순환 이미지보기를 만드는 방법

build.gradle

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.2" 

    defaultConfig { 
     applicationId "com.example.seng.healthyapp" 
     minSdkVersion 15 
     targetSdkVersion 23 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile 'com.android.support:appcompat-v7:23.1.1' 
    compile 'de.hdodenhof:circleimageview:2.1.0' 
    testCompile 'junit:junit:4.12' 
    compile 'com.google.android.gms:play-services-location:9.2.0' 

} 

register.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:gravity="center" 
    android:orientation="vertical"> 

    <de.hdodenhof.circleimageview.CircleImageView 
     android:id="@+id/imgProfilePicture" 
     android:layout_width="120dp" 
     android:layout_height="120dp" 
     android:layout_marginBottom="20dp" 
     app:civ_border_width="3dp" 
     app:civ_border_color="@color/white" 
     android:background="@mipmap/profile" /> 


    <EditText 
     android:id="@+id/editTextName" 
     android:layout_width="325dp" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="10dp" 
     android:background="@color/white" 
     android:hint="@string/hint_name" 
     android:padding="10dp" 
     android:singleLine="true" /> 

    <EditText 
     android:id="@+id/editTextPassword" 
     android:layout_width="325dp" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="10dp" 
     android:background="@color/white" 
     android:hint="@string/hint_password" 
     android:inputType="textPassword" 
     android:padding="10dp" 
     android:singleLine="true" /> 

    <!-- Login Button --> 

    <EditText 
     android:id="@+id/editTextConfirmPassword" 
     android:layout_width="325dp" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="10dp" 
     android:background="@color/white" 
     android:hint="@string/confirm_password" 
     android:inputType="textPassword" 
     android:padding="10dp"/> 

    <Button 
     android:id="@+id/buttonSave" 
     android:layout_width="325dp" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="20dp" 
     android:background="@color/blue" 
     android:text="Confirm" 
     android:textAllCaps="false" 
     android:textColor="@color/white" 
     android:textSize="15dp" /> 
</LinearLayout> 

enter image description here

답변

1

이 것 내가 때 비트 맵 둥글게 만들어, 나는 그것이 문제가 없었 이것을 달성하기 위해 노력하고 또한 원형 이미지 뷰를 시도했지만 이것은 m 것으로 나타났습니다. 사용하기 쉬운 광석

Bitmap book = BitmapFactory.decodeResource(getResources(),R.drawable.book); 

imageView.setImageBitmap(getRoundedBitmap(book)); 


public Bitmap getRoundedBitmap(Bitmap bitmap){ 
    Bitmap circleBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); 
    BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); 
    Paint paint = new Paint(); 
    paint.setShader(shader); 
    paint.setAntiAlias(true); 
    Canvas c = new Canvas(circleBitmap); 
    c.drawCircle(bitmap.getWidth()/2, bitmap.getHeight()/2, bitmap.getWidth()/2, paint); 
    return circleBitmap; 
} 
+0

내가 변수 비트 맵에 대한 놓아야 값이 무엇인지 알 수 있습니까? – Tony

+0

나는 내 awnser를 편집했다. Drawable에서 BitmapFactory.decodeResource를 사용할 수 있다면 몇 가지 방법으로 Bitmap을 만들 수있다. –

+0

고마워, 저에게 효과적이다. – Tony

0

직접 만드십시오. 그것은 바퀴를 재발 명하려는 것과 거의 같습니다.

제 3 자 라이브러리 중 하나를 사용하는 것이 좋습니다. 나는이 라이브러리를 프로덕션 코드에 사용했으며 훌륭하게 작동합니다. 여기

내가 사용하는 것을 몇 가지

https://github.com/lopspower/CircularImageView

https://github.com/hdodenhof/CircleImageView

+0

예, 제 3 자도 사용하고 있습니다. 제안 해 주셔서 감사 드리며 나중에 시도해 보겠습니다. – Tony