新增labelTextWidth
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
android:id="@+id/viewfinderView"
|
android:id="@+id/viewfinderView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
app:labelTextWidth="180dp"
|
||||||
app:labelText="@string/tips_scan_code"
|
app:labelText="@string/tips_scan_code"
|
||||||
app:labelTextSize="@dimen/size_14sp"
|
app:labelTextSize="@dimen/size_14sp"
|
||||||
app:laserColor="@color/colorAccent"
|
app:laserColor="@color/colorAccent"
|
||||||
|
|||||||
@@ -95,6 +95,10 @@ public class ViewfinderView extends View {
|
|||||||
* 提示文本与扫码框的边距
|
* 提示文本与扫码框的边距
|
||||||
*/
|
*/
|
||||||
private float labelTextPadding;
|
private float labelTextPadding;
|
||||||
|
/**
|
||||||
|
* 提示文本的宽度
|
||||||
|
*/
|
||||||
|
private int labelTextWidth;
|
||||||
/**
|
/**
|
||||||
* 提示文本的位置
|
* 提示文本的位置
|
||||||
*/
|
*/
|
||||||
@@ -288,6 +292,7 @@ public class ViewfinderView extends View {
|
|||||||
labelTextColor = array.getColor(R.styleable.ViewfinderView_labelTextColor, ContextCompat.getColor(context,R.color.viewfinder_text_color));
|
labelTextColor = array.getColor(R.styleable.ViewfinderView_labelTextColor, ContextCompat.getColor(context,R.color.viewfinder_text_color));
|
||||||
labelTextSize = array.getDimension(R.styleable.ViewfinderView_labelTextSize, TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,14f,getResources().getDisplayMetrics()));
|
labelTextSize = array.getDimension(R.styleable.ViewfinderView_labelTextSize, TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,14f,getResources().getDisplayMetrics()));
|
||||||
labelTextPadding = array.getDimension(R.styleable.ViewfinderView_labelTextPadding,TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,24,getResources().getDisplayMetrics()));
|
labelTextPadding = array.getDimension(R.styleable.ViewfinderView_labelTextPadding,TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,24,getResources().getDisplayMetrics()));
|
||||||
|
labelTextWidth = array.getDimensionPixelSize(R.styleable.ViewfinderView_labelTextWidth,0);
|
||||||
labelTextLocation = TextLocation.getFromInt(array.getInt(R.styleable.ViewfinderView_labelTextLocation,0));
|
labelTextLocation = TextLocation.getFromInt(array.getInt(R.styleable.ViewfinderView_labelTextLocation,0));
|
||||||
|
|
||||||
// isShowResultPoint = array.getBoolean(R.styleable.ViewfinderView_showResultPoint,false);
|
// isShowResultPoint = array.getBoolean(R.styleable.ViewfinderView_showResultPoint,false);
|
||||||
@@ -361,6 +366,10 @@ public class ViewfinderView extends View {
|
|||||||
frameHeight = size;
|
frameHeight = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(labelTextWidth <= 0){
|
||||||
|
labelTextWidth = width - getPaddingLeft() - getPaddingRight();
|
||||||
|
}
|
||||||
|
|
||||||
float leftOffsets = (width - frameWidth) / 2 + framePaddingLeft - framePaddingRight;
|
float leftOffsets = (width - frameWidth) / 2 + framePaddingLeft - framePaddingRight;
|
||||||
float topOffsets = (height - frameHeight) / 2 + framePaddingTop - framePaddingBottom;
|
float topOffsets = (height - frameHeight) / 2 + framePaddingTop - framePaddingBottom;
|
||||||
switch (frameGravity){
|
switch (frameGravity){
|
||||||
@@ -420,7 +429,7 @@ public class ViewfinderView extends View {
|
|||||||
textPaint.setColor(labelTextColor);
|
textPaint.setColor(labelTextColor);
|
||||||
textPaint.setTextSize(labelTextSize);
|
textPaint.setTextSize(labelTextSize);
|
||||||
textPaint.setTextAlign(Paint.Align.CENTER);
|
textPaint.setTextAlign(Paint.Align.CENTER);
|
||||||
StaticLayout staticLayout = new StaticLayout(labelText,textPaint,canvas.getWidth(), Layout.Alignment.ALIGN_NORMAL,1.0f,0.0f,true);
|
StaticLayout staticLayout = new StaticLayout(labelText,textPaint,labelTextWidth, Layout.Alignment.ALIGN_NORMAL,1.2f,0.0f,true);
|
||||||
if(labelTextLocation == TextLocation.BOTTOM){
|
if(labelTextLocation == TextLocation.BOTTOM){
|
||||||
canvas.translate(frame.left + frame.width() / 2,frame.bottom + labelTextPadding);
|
canvas.translate(frame.left + frame.width() / 2,frame.bottom + labelTextPadding);
|
||||||
}else{
|
}else{
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
<attr name="labelTextColor" format="color"/>
|
<attr name="labelTextColor" format="color"/>
|
||||||
<attr name="labelTextSize" format="dimension"/>
|
<attr name="labelTextSize" format="dimension"/>
|
||||||
<attr name="labelTextPadding" format="dimension"/>
|
<attr name="labelTextPadding" format="dimension"/>
|
||||||
|
<attr name="labelTextWidth" format="dimension"/>
|
||||||
<attr name="labelTextLocation" format="enum">
|
<attr name="labelTextLocation" format="enum">
|
||||||
<enum name="top" value="0"/>
|
<enum name="top" value="0"/>
|
||||||
<enum name="bottom" value="1"/>
|
<enum name="bottom" value="1"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user