添加 AutoWrapLayout 每行 baseLine top, center, bottom 功能

修正预览图下沿对齐
This commit is contained in:
seven332 committed 2014-03-25 11:50:42 +08:00
1 parent 556429a4d6
commit 7945b0facd
10 files changed
+101 -15

No files matched your search

+2 -2
View File
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hippo.ehviewer"
android:versionCode="8"
android:versionName="0.3.3" >
android:versionCode="9"
android:versionName="0.3.4" >
<uses-sdk
android:minSdkVersion="14"
+2 -2
View File
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hippo.ehviewer"
android:versionCode="8"
android:versionName="0.3.3" >
android:versionCode="9"
android:versionName="0.3.4" >
<uses-sdk
android:minSdkVersion="14"
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+3 -1
View File
@@ -1,4 +1,5 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:auto="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="12dp"
@@ -13,7 +14,8 @@
android:id="@+id/paper_list_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" >
android:layout_gravity="center"
auto:baseLine="bottom">
</com.hippo.ehviewer.widget.AutoWrapLayout>
<ProgressBar
+4
View File
@@ -1,3 +1,7 @@
Version 0.3.4 (2014-03-23)
* 完善用于显示预览图的自动换行控件
* 显示漫画标签组名
Version 0.3.3 (2014-03-23)
* 测试自动更新
* 修正没有时更新显示主机错误问题
+9 -3
View File
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="SuperImageView">
<declare-styleable name="SuperImageView">
<!-- Sets a drawable as the content of this ImageView. -->
<attr name="src" format="reference|color" />
<!-- Controls how the image should be resized or moved to match the size
of this ImageView. -->
<attr name="scaleType">
<enum name="matrix" value="0" />
<enum name="fitXY" value="1" /> <!-- error -->
<enum name="fitXY" value="1" />
<enum name="fitStart" value="2" />
<enum name="fitCenter" value="3" />
<enum name="fitEnd" value="4" />
@@ -44,6 +44,12 @@
<attr name="mask" format="reference" />
</declare-styleable>
<declare-styleable name="AutoWrapLayout">
<attr name="baseLine">
<enum name="top" value="0" />
<enum name="center" value="1" />
<enum name="bottom" value="2" />
</attr>
</declare-styleable>
</resources>
@@ -18,6 +18,7 @@ import com.hippo.ehviewer.util.Ui;
import com.hippo.ehviewer.util.Util;
import com.hippo.ehviewer.view.OlImageView;
import com.hippo.ehviewer.widget.AutoWrapLayout;
import com.hippo.ehviewer.widget.AutoWrapLayout.BaseLine;
import android.app.Activity;
import android.app.AlertDialog;
@@ -3,8 +3,11 @@ package com.hippo.ehviewer.widget;
import java.util.ArrayList;
import java.util.List;
import com.hippo.ehviewer.R;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
@@ -22,16 +25,77 @@ public class AutoWrapLayout extends ViewGroup {
private final static String TAG = "AutoWrapLayout";
private List<Rect> rectList = new ArrayList<Rect>();
private BaseLine mBaseLine;
private static final BaseLine[] sBaseLineArray = { BaseLine.TOP,
BaseLine.CENTER, BaseLine.BOTTOM };
public enum BaseLine {
TOP(0),
CENTER(1),
BOTTOM(2);
BaseLine(int ni) {
nativeInt = ni;
}
final int nativeInt;
}
public AutoWrapLayout(Context context) {
super(context);
}
public AutoWrapLayout(Context context, AttributeSet attrs) {
super(context, attrs);
this(context, attrs, 0);
}
public AutoWrapLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.AutoWrapLayout, defStyle, 0);
int index = a.getInt(R.styleable.AutoWrapLayout_baseLine, -1);
if (index >= 0)
setBaseLine(sBaseLineArray[index]);
a.recycle();
}
public void setBaseLine(BaseLine baseLine) {
if (baseLine == null)
return;
if (mBaseLine != baseLine) {
mBaseLine = baseLine;
requestLayout();
invalidate();
}
}
public BaseLine getScaleType() {
return mBaseLine;
}
private void adjustBaseLine(int lineHeight, int startIndex, int endIndex) {
if (mBaseLine == BaseLine.TOP)
return;
for (int index = startIndex; index < endIndex; index++) {
final View child = getChildAt(index);
final AutoWrapLayout.LayoutParams lp =
(AutoWrapLayout.LayoutParams)child.getLayoutParams();
Rect rect = rectList.get(index);
int offsetRaw = lineHeight - rect.height() - lp.topMargin - lp.bottomMargin;
if (mBaseLine == BaseLine.CENTER)
rect.offset(0, offsetRaw/2);
else if (mBaseLine == BaseLine.BOTTOM)
rect.offset(0, offsetRaw);
}
}
// TODO Take vertical mode
/**
* each row or line at least show one child
@@ -58,7 +122,7 @@ public class AutoWrapLayout extends ViewGroup {
int paddingBottom = getPaddingBottom();
int maxRightBound = maxWidth - paddingRight;
int maxBottomBound = maxWidth - paddingBottom;
int maxBottomBound = maxHeight - paddingBottom;
int left;
int top;
@@ -73,6 +137,9 @@ public class AutoWrapLayout extends ViewGroup {
int childWidth;
int childHeight;
int lineStartIndex = 0;
int lineEndIndex = 0; // endIndex + 1
rectList.clear();
int childCount = getChildCount();
for (int index = 0; index < childCount; index++) {
@@ -89,7 +156,11 @@ public class AutoWrapLayout extends ViewGroup {
right = left + childWidth;
rightBound = right + lp.rightMargin;
if (rightBound > maxRightBound) { // Go to next row
// If child can't show in parent
lineEndIndex = index;
// Adjust child position base on baseline
adjustBaseLine(maxBottom - lastMaxBottom, lineStartIndex, lineEndIndex);
// If child can't show in parent begin this line
if (maxBottom >= maxBottomBound)
break;
left = paddingLeft + lp.leftMargin;
@@ -100,6 +171,8 @@ public class AutoWrapLayout extends ViewGroup {
top = lastMaxBottom + lp.topMargin;
bottom = top + childHeight;
bottomBound = bottom + lp.bottomMargin;
lineStartIndex = index;
} else {
top = lastMaxBottom + lp.topMargin;
bottom = top + childHeight;
@@ -118,16 +191,16 @@ public class AutoWrapLayout extends ViewGroup {
rectList.add(rect);
}
// Handle last line baseline
adjustBaseLine(maxBottom - lastMaxBottom, lineStartIndex, rectList.size());
int measuredWidth;
int measuredHeight;
if (widthMode == MeasureSpec.EXACTLY)
measuredWidth = maxWidth;
else {
else
measuredWidth = maxRightNoPadding + paddingRight;
if (widthMode == MeasureSpec.AT_MOST)
measuredWidth = measuredWidth > maxWidth ? maxWidth : measuredWidth;
}
if (heightMode == MeasureSpec.EXACTLY)
measuredHeight = maxHeight;
else {