简体   繁体   English

ImageView 在 Android 中没有变化

[英]ImageView not changing in Android

i am making a facebook login page, importing image too, my code:我正在制作 facebook 登录页面,也导入图像,我的代码:

 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:和图像的 xml :

   <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我尝试使用Picasso更改照片但不起作用
i tried using a photo i have used before R.drawable.abs , doesn't work also我尝试使用在R.drawable.abs之前使用过的照片,也不起作用
changing the hieght of the imageview works改变 imageview 作品的高度

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:不确定为什么需要 xml 中的前景,但您应该能够在 java 代码中将其替换为:

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 itandroid:foreground更改为app:srcCompat解决它

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

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