Skip to content

Commit

Permalink
更新
Browse files Browse the repository at this point in the history
  • Loading branch information
luhaoaimama1 committed Aug 6, 2020
1 parent 3b97359 commit 7eda6f9
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 6 deletions.
29 changes: 23 additions & 6 deletions Android_Zone_Test/res/layout/a_bbbb_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:onClick="onClick"
android:backgroundTint="@color/font_focus"
android:onClick="onClick"
android:text="精彩嵌套滚动" />


Expand All @@ -24,12 +24,29 @@
android:text="page传递" />

<view.TextViewLineSpacingFix
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:background="#00ff00"
android:layout_width="match_parent"
android:lineSpacingMultiplier="@dimen/card_warning_text_extra_space"
android:layout_height="match_parent"
android:text="a哇咔咔卡卡卡卡卡啊,a哇咔咔卡卡卡卡卡啊a哇咔咔卡卡卡卡卡啊a哇咔咔卡卡卡卡卡啊"/>
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:text="a哇咔咔卡卡卡卡卡啊,a哇咔咔卡卡卡卡卡啊a哇咔咔卡卡卡卡卡啊a哇咔咔卡卡卡卡卡啊" />


<TextView
style="@style/TvHint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="KY" />

<view.BGTextView
android:lineSpacingExtra="30dp"
android:textSize="16sp"
android:background="@null"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:text="我的天 \n我的天2 \n我的天3 " />
</com.zone.view.FlowLayout>
57 changes: 57 additions & 0 deletions Android_Zone_Test/src/view/BGTextView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.text.Layout;
import android.util.AttributeSet;

import androidx.annotation.Nullable;

import com.zone.lib.utils.view.DrawUtils;

public class BGTextView extends androidx.appcompat.widget.AppCompatEditText {
public BGTextView(Context context) {
super(context);
}

public BGTextView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}

public BGTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

Paint paint2 = DrawUtils.getStrokePaint(Paint.Style.STROKE, 3);
int[] colorArry = new int[]{Color.CYAN, Color.GREEN, Color.YELLOW};
Rect rect = new Rect();

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
setMeasuredDimension(getMeasuredWidth(), (int) (getMeasuredHeight() + getLineSpacingExtra()));
}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
float lineSpacingExtra = getLineSpacingExtra();
try {
Layout layout = getLayout();
int lineCount = layout.getLineCount();
for (int i = 0; i < lineCount; i++) {
paint2.setColor(colorArry[i % colorArry.length]);
layout.getLineBounds(i, rect);
if (i == lineCount - 1) {
rect.bottom += lineSpacingExtra;
}
canvas.drawRect(rect, paint2);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

0 comments on commit 7eda6f9

Please sign in to comment.