Java 在Android Studio中,如何更改带有圆形边框的google帐户的照片?

Java 在Android Studio中,如何更改带有圆形边框的google帐户的照片?,java,android,android-studio,navigation-drawer,android-navigationview,Java,Android,Android Studio,Navigation Drawer,Android Navigationview,我将帐户的照片放在导航标题中。边框是长方形的,我想把它做成圆形,我该怎么做? 在这段代码中,我使用Glide来显示图像 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/

我将帐户的照片放在导航标题中。边框是长方形的,我想把它做成圆形,我该怎么做? 在这段代码中,我使用Glide来显示图像

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>

你的代码是对的,你需要实现CircleImageView,我告诉你如何实现

nav_header_main.xml

带CircleImageView的我的导航抽屉

注意
请记住,您的图像需要按比例标注尺寸,例如(100x100,200x200),就像一个完美的正方形,我希望我能帮助您。

谢谢的家伙,它适合我!但是如果没有下面的作业,我不知道为什么
app:civ_border_color=“#EEEEEE”app:civ_border_width=“4dp”app:civ_shadow=“true”app:civ_shadow_radius=“10”app:civ_shadow_color=“#8BC34A”
您需要在外部线性布局或相对性中声明app变量。它取决于您的设计,我会编辑我的答案,现在检查它,如果可以的话,请把我的答案投+1
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);

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