[英]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.