简体   繁体   English

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

[英]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. 在这段代码中,我使用了Glide来显示图像。

my_header_navigation.xml 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,我将向您展示如何实现。

CircleImageView - GitHub CircleImageView-GitHub

nav_header_main.xml 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 我的CircleImageView的NavigationDrawer

Link Image 连结图片

NOTE Remember, your image need proportional dimensioned, example (100x100, 200x200), like a perfect square, I hope I have help you. 注意请记住,您的图像需要按比例缩放,例如(100x100、200x200),就像一个完美的正方形,希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何以编程方式向我的ImageView添加圆角边框? - How can I programatically add a rounded border to my ImageView? 如何在具有Google帐户的Android中使用AccountManager? - How can I use AccountManager in Android with Google Account? Android,如何为ImageButton实现圆角,然后以编程方式更改颜色? - Android, how can I implement rounded corners for ImageButton and then change the color programatically? 如何打开用户的相机并将其打开,但不能在 Android Studio 上拍照 - How can I open a user's camera and have it open, but NOT to take a photo on Android Studio 在 android 中为图像添加边框,如谷歌照片扫描应用程序 - Adding border to image like google photo scan app in android 如何通过 Android Studio 中的 WebView 实现 Google Maps - How can I implement Google Maps through a WebView in Android Studio 如何更改 Android Studio 中的字体大小? - How can I change the font size in Android Studio? Android:如何验证我的Google帐户以及如何获取我的GMail任务? - Android: how do I authenticate to my google account and how can I get my GMail Tasks? 在 Android Studio 中,如何将应用项目更改为库? - in Android Studio, how can I change an app project to a library? 我怎样才能改变java版本(android studio) - how can I change java version(android studio)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM