簡體   English   中英

ImageView 在 Android 中沒有變化

[英]ImageView not changing in Android

我正在制作 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

        }

和圖像的 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"/>

我嘗試使用Picasso更改照片但不起作用
我嘗試使用在R.drawable.abs之前使用過的照片,也不起作用
改變 imageview 作品的高度

那么有什么問題呢?

不確定為什么需要 xml 中的前景,但您應該能夠在 java 代碼中將其替換為:

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

加載圖像后,這將替換占位符。

android:foreground更改為app:srcCompat解決它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM