案例: 我在app上工作,根据Foursquare API的坐标检索有关本地场地的信息。所有信息都存储在数据库中,包括存储为前缀和链接后缀的场地特色照片。对于列表表示,我使用了recyclerview。我记录了url链接,看起来工作正常。这是我的onBindViewHolder方法:
public void onBindViewHolder(ViewHolder holder, int position) {
if (holder instanceof ItemViewHolder) {
Venue venue = venueList.get(position);
String url = venue.getFeaturedPhotos().getItems().get(0).getPrefix() + "120x120" + venue.getFeaturedPhotos().getItems().get(0).getSuffix();
((ItemViewHolder) holder).venueName.setText(venue.getName());
((ItemViewHolder) holder).streetAdr.setText(venue.getLocation().getAddress());
((ItemViewHolder) holder).rating.setText(venue.getRating().toString());
Context context = ((ItemViewHolder) holder).venuePhoto.getContext();
Picasso.with(context).load(url).into(((ItemViewHolder) holder).venuePhoto);;
((ItemViewHolder) holder).venue = venue;
} else {
((ProgressViewHolder) holder).progressBar.setIndeterminate(true);
}
}
这是我的项目的样子:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="@+id/venuePhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:contentDescription="@string/imgDescr"
/>
<TextView
android:id="@+id/rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="@string/ratingSample"
android:textSize="45sp" />
<TextView
android:id="@+id/venueName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@id/rating"
android:layout_toRightOf="@id/venuePhoto"
android:text="@string/VenueNameSample"
android:textSize="20sp" />
<TextView
android:id="@+id/streetAdr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/venueName"
android:layout_toLeftOf="@id/rating"
android:layout_toRightOf="@id/venuePhoto"
android:text="@string/addressSample"
android:textSize="20sp" />
</RelativeLayout>
答案 0 :(得分:0)
我通过添加uri解析
找到了解决方案String url = venue.getFeaturedPhotos().getItems().get(0).getPrefix() + "120x120" + venue.getFeaturedPhotos().getItems().get(0).getSuffix();
Uri uri = Uri.parse(url);