简体   繁体   中英

In Android Studio how can I change the photo of the google account with the rounded border?

I put the photo of the account in the navigation header. The border is rectangular, I would like to make it rounded, how can I do that? In this code I used Glide to display the image.

my_header_navigation.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="140dp"
android:background="@color/common_google_signin_btn_text_dark_focused"
android:id="@+id/navigation_header">

<ImageView
    android:id="@+id/photoImageView"
    android:layout_width="56dp"
    android:layout_height="56dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentStart="true"
    android:layout_marginBottom="16dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginStart="18dp"
    android:background="@color/colorAccent"
    android:visibility="invisible" />

</RelativeLayout>

and in the Main Activity:

private ImageView photoImageView;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list);

    View hView = navigationView.getHeaderView(0);
    photoImageView = hView.findViewById(R.id.photoImageView);


    if(user != null){
        Glide.with(List.this).load(user.getPhotoUrl()).into(photoImageView);

        photoImageView.setVisibility(View.VISIBLE);
    }
    else{

        photoImageView.setVisibility(View.INVISIBLE);

    }

Your code i'ts right, you need implement CircleImageView, I show you how to implement.

CircleImageView - GitHub

nav_header_main.xml

<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="@dimen/nav_header_height"
    android:background="@drawable/side_nav_bar"
    android:gravity="bottom"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:theme="@style/ThemeOverlay.AppCompat.Dark">

    <com.mikhaellopez.circularimageview.CircularImageView
            android:id="@+id/profile_image"
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:src="@drawable/profile_image"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="20dp"
            android:layout_marginBottom="0dp"
            app:civ_border_color="#EEEEEE"
            app:civ_border_width="4dp"
            app:civ_shadow="true"
            app:civ_shadow_radius="10"
            app:civ_shadow_color="#8BC34A"/>

</LinearLayout>

MainActivity

    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            CircleImageView circleImageView = (CircleImageView) findViewById(R.id.profile_image);
            Glide.with(List.this).load(user.getPhotoUrl()).into(circleImageView);
    }

My NavigationDrawer with CircleImageView

Link Image

NOTE Remember, your image need proportional dimensioned, example (100x100, 200x200), like a perfect square, I hope I have help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM