简体   繁体   中英

ImageView not changing in Android

i am making a facebook login page, importing image too, my code:

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    info = findViewById(R.id.info);
    profile = findViewById(R.id.profile);
    login = findViewById(R.id.login_button);

    callbackManager=CallbackManager.Factory.create();

    login.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            String usrid=loginResult.getAccessToken().getUserId();
            info.setText("user ID: "+usrid);


            profile.setImageResource(R.drawable.abs);//doesn't work
            profile.getLayoutParams().height=20;//it's work


            String imgURL ="https://graph.facebook.com/"+usrid+"/picture?type=large";
            Picasso.get().load(imgURL).fit().into(profile);//does not work

        }

and the xml of the image:

   <ImageView
    android:id="@+id/profile"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_marginTop="50dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.498"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/info"
    android:foreground="@drawable/ic_launcher_background"/>

i tried to change the photo using Picasso but doesn't work
i tried using a photo i have used before R.drawable.abs , doesn't work also
changing the hieght of the imageview works

so what is wrong?

Not sure why the forground in your xml is needed but you should be able to replace it with this in your java code:

Picasso.get()
.load(imgURL)
.placeholder(R.drawable. ic_launcher_background)
.fit()
.into(profile);

This will replace the placeholder once the image is loaded.

changing android:foreground to app:srcCompat solve it

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