Creating profile pic in Navigation drawer
First Implement Navigation Drawer in your project.
NavigationDrawer.java
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); View header=navigationView.getHeaderView(0); imageView=header.findViewById(R.id.imageView); Picasso.with(this).load("https://fmc-gac.com/wp/wp-content/uploads/fmc/farmer%20w%20produce.jpg").transform(new CircleTransform()).into(imageView);
nav_header_nav_drawer.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="200dp" android:background="@color/colorPrimaryDark" android:gravity="center" android:orientation="vertical" android:theme="@style/ThemeOverlay.AppCompat.Dark"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:id="@+id/imageView" android:layout_width="64dp" android:layout_height="64dp" android:layout_marginLeft="20dp" android:layout_marginBottom="15dp" android:layout_gravity="bottom" app:srcCompat="@drawable/ic_farmer"/> </LinearLayout> </LinearLayout>CircleTransform.java - Class for implementing circular view in imageview
package <your_package_name>;import android.graphics.Bitmap; import android.graphics.BitmapShader; import android.graphics.Canvas; import android.graphics.Paint; import com.squareup.picasso.Transformation; public class CircleTransform implements Transformation { @Override public Bitmap transform(Bitmap source) { int size = Math.min(source.getWidth(), source.getHeight()); int x = (source.getWidth() - size) / 2; int y = (source.getHeight() - size) / 2; Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size); if (squaredBitmap != source) { source.recycle(); } Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig()); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP); paint.setShader(shader); paint.setAntiAlias(true); float r = size / 2f; canvas.drawCircle(r, r, r, paint); squaredBitmap.recycle(); return bitmap; } @Override public String key() { return "circle"; } }Link : Circular ImageView In Navigation Drawer
Comments
Post a Comment