使用带有圆形图像视图的毕加索库 [英] Using picasso library with a circle image view
问题描述
我正在使用Picasso库从URL下载图像并将其传递到圆形图像视图,但由于毕加索要求您传入实际的图像视图,我已经停止了如何做到这一点
I am looking at using the Picasso library to download an image from URL and pass this into circle image view, but since picasso requires that you pass in an actual imageView I have come to a standstill on how to do it
我在这里使用毕加索图书馆 http://square.github.io/picasso /
和此处的圆形图像视图类 https://github.com/hdodenhof/CircleImageView
I am using the picasso library from here http://square.github.io/picasso/ and the circle image view class from here https://github.com/hdodenhof/CircleImageView
以下是获取图片的代码的开头
Here is the start of my code to get the image
private void getData() {
userName.setText(prefs.getString("userName",""));
jobTitle.setText(prefs.getString("profile",""));
userLocation.setText(prefs.getString("location",""));
// ??????
// Picasso.with(context).load(image link here).into(imageview here);
//CircleImageView img = new CircleImageView(this);
//img.setImageResource();
//img.setImageBitmap();
//img.setImageDrawable();
//img.setImageURI();
}
编辑:
这里是circleImageView的xml
here is the xml for the circleImageView
<michael.CircleImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/shadow"
android:layout_gravity="center"
android:layout_marginTop="16dp"
app:border_width="2dp"
app:border_color="#274978"
android:id="@+id/circleImageView"
推荐答案
使用此
活动类
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String imageUrl = "https://www.baby-connect.com/images/baby2.gif";
CircleImageView imageView = (CircleImageView) findViewById(R.id.image);
Picasso.with(getApplicationContext()).load(imageUrl)
.placeholder(R.drawable.images).error(R.drawable.ic_launcher)
.into(imageView);
}
}
布局文件
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/image"
android:layout_width="160dp"
android:layout_height="160dp"
android:layout_centerInParent="true"
android:src="@drawable/images"
app:border_color="#ffffff"
app:border_width="2dp" />
这是工作正常。
这篇关于使用带有圆形图像视图的毕加索库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!