Commit 4de1f4cf by 段启岩

DynamicGridLayout更新-计算padding

parent e86dea51
......@@ -99,7 +99,9 @@ public class DynamicGridLayout extends ViewGroup {
}
// 计算布局尺寸
int maxWidth = MeasureSpec.getSize(getMeasuredWidth());
int measuredWidth = MeasureSpec.getSize(getMeasuredWidth());
int maxWidth = measuredWidth - (getPaddingLeft() + getPaddingRight());
// 每个图片的尺寸
int imageSize = (maxWidth - (mCol - 1) * mSpacing) / mCol;
......@@ -108,7 +110,7 @@ public class DynamicGridLayout extends ViewGroup {
imageSize = (int) (imageSize * 0.66);
}
int layoutHeight = imageSize * mRow + (mRow - 1) * mSpacing;
int layoutHeight = imageSize * mRow + (mRow - 1) * mSpacing + getPaddingTop() + getPaddingBottom();
LayoutParams layoutParams = getLayoutParams();
layoutParams.height = layoutHeight;
......@@ -121,8 +123,8 @@ public class DynamicGridLayout extends ViewGroup {
currentCol = i - (currentRow * mCol);
ImageView imageView = createImageView(mImgUrls.get(i));
this.addView(imageView, new LayoutParams(imageSize, imageSize));
int left = computePosition(currentCol, imageSize);
int top = computePosition(currentRow, imageSize);
int left = computePosition(currentCol, imageSize) + getPaddingLeft();
int top = computePosition(currentRow, imageSize) + getPaddingTop();
imageView.layout(left, top, left + imageSize, top + imageSize);
}
isImageInit = true;
......@@ -157,7 +159,7 @@ public class DynamicGridLayout extends ViewGroup {
}
if (imageHeight != -1 && imageHeight != layoutParams.height) {
layoutParams.height = imageHeight;
layoutParams.height = imageHeight + getPaddingTop() + getPaddingBottom();
setLayoutParams(layoutParams);
}
......
......@@ -58,6 +58,7 @@
<TextView
android:id="@+id/txt_content"
android:layout_marginTop="10dp"
android:paddingBottom="14dp"
android:text="SpringBoot迭代发布JRA瘦身配置"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
......@@ -83,7 +84,7 @@
<cn.yunliyunwai.beyondclouds.view.DynamicGridLayout
android:id="@+id/dynamic_grid_layout"
android:layout_marginTop="14dp"
android:paddingBottom="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/barrier_content"
......@@ -97,7 +98,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<View
android:layout_marginTop="18dp"
android:layout_marginTop="4dp"
app:layout_constraintTop_toBottomOf="@id/barrier_dynamic_grid"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment