Skip to content

Commit

Permalink
KrvLineView新增textLayoutAlignment 属性。
Browse files Browse the repository at this point in the history
  • Loading branch information
censhengde committed Oct 16, 2023
1 parent a8f7081 commit a2d1127
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion krcview/src/main/java/com/bytedance/krcview/KrcLineView.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.text.Layout;
import android.text.Layout.Alignment;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.util.AttributeSet;
Expand Down Expand Up @@ -45,6 +46,10 @@ public class KrcLineView extends View implements AnimatorUpdateListener, LineHol
private LineHolder lineHolder;




private Layout.Alignment textLayoutAlignment = Alignment.ALIGN_CENTER;

public KrcLineView(Context context) {
this(context, null);
}
Expand All @@ -60,6 +65,14 @@ public KrcLineView(Context context, @Nullable AttributeSet attrs, int defStyleAt
}


public void setTextLayoutAlignment(Alignment textLayoutAlignment) {
this.textLayoutAlignment = textLayoutAlignment;
}

public Alignment getTextLayoutAlignment() {
return textLayoutAlignment;
}

@Override
public void attachedViewHolder(@NonNull LineHolder holder) {
lineHolder = holder;
Expand Down Expand Up @@ -105,7 +118,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

if (staticLayout == null || !staticLayout.getText().equals(krcLineInfo.text)) {
staticLayout = new StaticLayout(krcLineInfo.text, lineTextPaint, (int) maxWordsWidth,
Layout.Alignment.ALIGN_CENTER, 1f, 0.0f, false);
textLayoutAlignment, 1f, 0.0f, false);
}

if (widthMeasureMode == MeasureSpec.AT_MOST || widthMeasureMode == MeasureSpec.UNSPECIFIED) {
Expand Down

0 comments on commit a2d1127

Please sign in to comment.