Skip to content

Commit

Permalink
update bug add gif
Browse files Browse the repository at this point in the history
  • Loading branch information
陈鹏飞 committed Nov 4, 2016
1 parent 35ca512 commit 2aae8b8
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 28 deletions.
3 changes: 0 additions & 3 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Expand Up @@ -8,7 +8,7 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name=".MainActivity" android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
31 changes: 10 additions & 21 deletions app/src/main/java/com/fe/verticalmarqueeview/MarqueeView.java
Expand Up @@ -17,8 +17,6 @@
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import java.util.ArrayList;
import java.util.List;

/**
* Created by chenepengfei on 2016/11/3.
Expand Down Expand Up @@ -93,12 +91,12 @@ public class MarqueeView extends View {
/**
* 文本最大的宽度
*/
private Rect mTextMaxRect;
private int mTextMaxWidth;

/**
* 文本rect集合
* 文本高度
*/
private List<Rect> mTextRectList;
private int mTextHeight;

/**
* 画笔
Expand Down Expand Up @@ -191,7 +189,7 @@ private int getViewWidth(ViewGroup.LayoutParams lp, int pWidth) {
if(lp.width >= 0) {
width = lp.width;
} else if(lp.width == ViewGroup.LayoutParams.WRAP_CONTENT){
width = mTextMaxRect.width() + mPaddingLeft;
width = mTextMaxWidth + mPaddingLeft;
} else if(lp.width == ViewGroup.LayoutParams.MATCH_PARENT) {
width = pWidth;
}
Expand All @@ -203,7 +201,7 @@ private int getViewHeight(ViewGroup.LayoutParams lp, int pHeight) {
if(lp.height >= 0) {
height = lp.height;
} else if(lp.height == ViewGroup.LayoutParams.WRAP_CONTENT) {
height = mTextMaxRect.height() + mPaddingTop + mPaddingBottom;
height = mTextHeight + mPaddingTop + mPaddingBottom;
} else if(lp.height == ViewGroup.LayoutParams.MATCH_PARENT) {
height = pHeight;
}
Expand All @@ -229,23 +227,15 @@ public void setTextArray(String[] textArray) {
}

private void initTextRect() {
if(mTextRectList == null) {
mTextRectList = new ArrayList<>(mTextArray.length);
} else {
if(mTextRectList.size() > 0) mTextRectList.clear();
}
int size = mTextArray.length;
for(int i = 0; i < size; i++) {
String text = mTextArray[i];
Rect rect = new Rect();
mPaint.getTextBounds(text, 0, text.length(), rect);
mTextRectList.add(rect);
if(mTextMaxRect == null) {
mTextMaxRect = rect;
} else {
if(rect.width() > mTextMaxRect.width())
mTextMaxRect = rect;
}
if(mTextHeight == 0)
mTextHeight = rect.height();
if(rect.width() > mTextMaxWidth)
mTextMaxWidth = rect.width();
}
}

Expand All @@ -263,7 +253,7 @@ private void setTextCurrentOrNextStatus(int currentPosition, int nextPosition, b
@Override
public void onGlobalLayout() {
mCurrentTextInitMarginTop = mCurrentTextMoveMarginTop = getFontBaseLine();
mNextTextInitMarginTop = mNextTextMoveMarginTop = mTextRectList.get(0).height() + getMeasuredHeight();
mNextTextInitMarginTop = mNextTextMoveMarginTop = mTextHeight + getMeasuredHeight();
mTextMoveOffset = mNextTextInitMarginTop - mCurrentTextInitMarginTop;
}
});
Expand Down Expand Up @@ -299,7 +289,6 @@ public void run() {
va.resume();
}
}, reRepeatDelayTime);

}
});
va.setRepeatCount(-1);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/bg_marqueeview.xml
Expand Up @@ -2,5 +2,5 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="@android:color/white" />
<stroke android:color="@android:color/black" android:width="1px"/>
<stroke android:color="#cccccc" android:width="1px"/>
</shape>
Binary file added app/src/main/res/drawable/xg.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 12 additions & 2 deletions app/src/main/res/layout/activity_main.xml
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

Expand All @@ -8,6 +10,14 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/bg_marqueeview"/>
android:background="@drawable/bg_marqueeview"
app:textSize="16sp"
app:textColor="#333333"
app:paddingLeft="10dp"
app:paddingTopBottom="15dp"
app:startDelayTime="500"
app:reRepeatDelayTime="1000"
app:itemAnimationTime="700"
/>

</RelativeLayout>

0 comments on commit 2aae8b8

Please sign in to comment.