Skip to content

Commit

Permalink
修正九宫格宽高偏差问题
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfusheng committed Jun 27, 2018
1 parent 2473cdd commit c668728
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ private void line1() {
}

private void line2() {
image21.fitCenter().load(gif1);
image22.fitCenter().load(gif2, R.mipmap.image_loading, 10);
image21.fitCenter().load(gif2, R.mipmap.image_loading, 10);
image22.fitCenter().load(gif1);
image23.fitCenter().loadCircle(gif3);
image24.fitCenter().loadDrawable(R.drawable.gif_robot_walk);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapt

RecyclerViewAdapter(Context context, List<ImageModel> list) {
this.list = list;
margin = Utils.dp2px(context, 4);
margin = Utils.dp2px(context, 3);
maxImgHeight = maxImgWidth = (Utils.getWindowWidth(context) - Utils.dp2px(context, 16) * 2) * 3 / 4;
cellHeight = cellWidth = (maxImgWidth - margin * 3) / 3;
minImgHeight = minImgWidth = cellWidth;
Expand All @@ -67,7 +67,7 @@ public void onBindViewHolder(@NonNull ViewHolder viewHolder, int position) {

viewHolder.vDesc.setText(model.desc);
viewHolder.multiImageView.loadGif(false)
.enableRoundCorner(false)
.enableRoundCorner(true)
.setRoundCornerRadius(5)
.setData(model.images, getLayoutHelper(model.images));

Expand All @@ -87,14 +87,13 @@ private GridLayoutHelper getLayoutHelper(List<ImageData> list) {
int width = list.get(0).realWidth;
int height = list.get(0).realHeight;
if (width > 0 && height > 0) {
float whRatio = width * 1f / height;
if (width > height) {
width = Math.max(minImgWidth, Math.min(width, maxImgWidth));
height = (int) (height * width * 1f / width);
height = (int) Math.max(width / 3f, height);
height = Math.max(minImgHeight, (int) (width / whRatio));
} else {
height = Math.max(minImgHeight, Math.min(height, maxImgHeight));
width = (int) (width * height * 1f / height);
width = (int) Math.max(height / 3f, width);
width = Math.max(minImgWidth, (int) (height * whRatio));
}
} else {
width = cellWidth;
Expand Down

0 comments on commit c668728

Please sign in to comment.