Picasso로 이미지를로드하기 전에 ImageView 높이를 설정하려고합니다. 상위 뷰가 이미지 높이를 변경하지 못하게하려고합니다. 나는 이미지의 높이와 너비를 얻고 Picasso 내부에 설정 한 다음 크기를 줄입니다.Recyccerview StaggeredGridLayout 내부에서 Picasso로 이미지를로드하기 전에 ImageView 높이 및 너비를 설정하는 방법
크기 조정을 방지하기 위해 Picasso로 이미지를로드하기 전에 "webformatHeight"및 "webformatWidth"를 기반으로 ImageView의 배율을 조정하는 방법은 무엇입니까?
데이터
{
...
"hits":[
{
"webformatHeight":426,
"webformatWidth":640,
"webformatURL":"https://pixabay.com/get/eb32b5062dfd013ed95c4518b74a4291ea77ead204b0144190f8c478a2ebb3_640.jpg",
...
},
...
]
}
리사이클 구현
RecyclerView recycler = (RecyclerView) findViewById(R.id.recycler);
mPixabayAdapter = new PixabayAdapter();
recycler.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
recycler.setAdapter(mPixabayAdapter);
ViewHolder
,class ViewHolder extends RecyclerView.ViewHolder {
private ImageView mImage;
private TextView mTitle;
private ViewHolder(View view) {
super(view);
mImage = view.findViewById(R.id.image);
mTitle = view.findViewById(R.id.title);
}
void bindView() {
ColorDrawable[] shotLoadingPlaceholders = new ColorDrawable[]{new ColorDrawable(ContextCompat.getColor(itemView.getContext(), R.color.background_light))};
Hit hit = mHitList.get(getAdapterPosition());
mTitle.setText(hit.getUser());
Picasso
.with(mImage.getContext())
.load(hit.getWebformatURL())
.placeholder(shotLoadingPlaceholders[0])
.resize(hit.getImageWidth(), hit.getImageHeight())
.priority(Picasso.Priority.HIGH)
.onlyScaleDown()
.into(mImage);
}
}
XML
<?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="wrap_content"
android:padding="4dp">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true" />
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_below="@+id/image"
android:background="@color/background_light"
android:fontFamily="sans-serif-medium"
android:gravity="center_vertical"
android:maxLines="1"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textColor="@color/white_light"
android:textSize="13sp" />
</RelativeLayout>
대단히 고마워요. 다른 사람들이 같은 문제를 겪는다면 도움이 될 수 있도록 코드를 정리했습니다. –