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