Skip to content

Commit

Permalink
// 单图的宽高设定更改
Browse files Browse the repository at this point in the history
  • Loading branch information
razerdp committed Dec 8, 2016
1 parent 747f1e0 commit d13850e
Showing 1 changed file with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.content.Context;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.util.Log;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -67,8 +66,10 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int childRestWidth = widthSize - getPaddingLeft() - getPaddingRight();
updateItemCount();
multiChildSize = childRestWidth / 3 - itemMargin * 2;
maxSingleWidth = childRestWidth * 2 / 3;
maxSingleHeight = (int) (maxSingleWidth / singleAspectRatio);
if (maxSingleWidth == 0) {
maxSingleWidth = childRestWidth * 2 / 3;
maxSingleHeight = (int) (maxSingleWidth / singleAspectRatio);
}

if (mDataChanged) {
if (mAdapter == null || mItemCount == 0) {
Expand Down Expand Up @@ -137,8 +138,8 @@ private void fillFourViews() {

private void setupViewAndAddView(int position, @NonNull ImageView v, boolean newLine, boolean isSingle) {
setItemLayoutParams(v, newLine, isSingle);
if (onSetUpChildLayoutParams != null) {
onSetUpChildLayoutParams.onSetUpParams(v, (LayoutParams) v.getLayoutParams(), position, isSingle);
if (onSetUpChildLayoutParamsListener != null) {
onSetUpChildLayoutParamsListener.onSetUpParams(v, (LayoutParams) v.getLayoutParams(), position, isSingle);
}
mAdapter.onBindData(position, v);
if (v.isLayoutRequested()) {
Expand Down Expand Up @@ -304,6 +305,9 @@ public float getSingleAspectRatio() {
}

public void setSingleAspectRatio(float singleAspectRatio) {
if (this.singleAspectRatio != singleAspectRatio && maxSingleWidth != 0) {
this.maxSingleHeight = (int) (maxSingleWidth / singleAspectRatio);
}
this.singleAspectRatio = singleAspectRatio;
}

Expand All @@ -323,18 +327,18 @@ public void setMaxSingleHeight(int maxSingleHeight) {
this.maxSingleHeight = maxSingleHeight;
}

public OnSetUpChildLayoutParams getOnSetUpChildLayoutParams() {
return onSetUpChildLayoutParams;
public OnSetUpChildLayoutParamsListener getOnSetUpChildLayoutParamsListener() {
return onSetUpChildLayoutParamsListener;
}

public void setOnSetUpChildLayoutParams(OnSetUpChildLayoutParams onSetUpChildLayoutParams) {
this.onSetUpChildLayoutParams = onSetUpChildLayoutParams;
public void setOnSetUpChildLayoutParamsListener(OnSetUpChildLayoutParamsListener onSetUpChildLayoutParamsListener) {
this.onSetUpChildLayoutParamsListener = onSetUpChildLayoutParamsListener;
}

//------------------------------------------Interface-----------------------------------------------
private OnSetUpChildLayoutParams onSetUpChildLayoutParams;
private OnSetUpChildLayoutParamsListener onSetUpChildLayoutParamsListener;

public interface OnSetUpChildLayoutParams {
public interface OnSetUpChildLayoutParamsListener {
void onSetUpParams(ImageView child, LayoutParams p, int position, boolean isSingle);
}
}

0 comments on commit d13850e

Please sign in to comment.