From 4cd35941ac38059d38bb242edf23dbbaebaf7bc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=A3=E5=AE=8F=E5=AE=87?= Date: Thu, 13 May 2021 13:20:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=BD=91=E7=BA=A6=E8=BD=A6?= =?UTF-8?q?=E7=9A=84=E6=BB=91=E5=8A=A8View=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mogo/och/view/SlidePanelView.java | 24 +++++++++++++------ .../layout/module_mogo_och_base_fragment.xml | 11 +++++++-- .../res/values-xhdpi-2560x1600/dimens.xml | 8 +++++++ OCH/mogo-och/src/main/res/values/attrs.xml | 12 ++++++++++ OCH/mogo-och/src/main/res/values/dimens.xml | 8 +++++++ 5 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 OCH/mogo-och/src/main/res/values/attrs.xml diff --git a/OCH/mogo-och/src/main/java/com/mogo/och/view/SlidePanelView.java b/OCH/mogo-och/src/main/java/com/mogo/och/view/SlidePanelView.java index db76a5e9f3..ee4785e198 100644 --- a/OCH/mogo-och/src/main/java/com/mogo/och/view/SlidePanelView.java +++ b/OCH/mogo-och/src/main/java/com/mogo/och/view/SlidePanelView.java @@ -3,6 +3,7 @@ package com.mogo.och.view; import android.animation.ObjectAnimator; import android.animation.ValueAnimator; import android.content.Context; +import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; @@ -41,6 +42,14 @@ public class SlidePanelView extends View { public SlidePanelView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); + TypedArray mTypedArray = context.obtainStyledAttributes(attrs, R.styleable.SlidePanelView); + textSize = (int) mTypedArray.getDimension(R.styleable.SlidePanelView_textSize, textSize); + BLOCK_START_X = (int) mTypedArray.getDimension(R.styleable.SlidePanelView_BLOCK_START_X, BLOCK_START_X); + BLOCK_START_Y = (int) mTypedArray.getDimension(R.styleable.SlidePanelView_BLOCK_START_Y, BLOCK_START_Y); + NORMAL_TEXT_MARGIN_LEFT = (int) mTypedArray.getDimension(R.styleable.SlidePanelView_NORMAL_TEXT_MARGIN_LEFT, NORMAL_TEXT_MARGIN_LEFT); + NORMAL_TEXT_MARGIN_RIGHT = (int) mTypedArray.getDimension(R.styleable.SlidePanelView_NORMAL_TEXT_MARGIN_RIGHT, NORMAL_TEXT_MARGIN_RIGHT); + SHORT_TEXT_MARGIN_LEFT = (int) mTypedArray.getDimension(R.styleable.SlidePanelView_SHORT_TEXT_MARGIN_LEFT, SHORT_TEXT_MARGIN_LEFT); + SHORT_TEXT_MARGIN_RIGHT = (int) mTypedArray.getDimension(R.styleable.SlidePanelView_SHORT_TEXT_MARGIN_RIGHT, SHORT_TEXT_MARGIN_RIGHT); init(); } @@ -48,12 +57,13 @@ public class SlidePanelView extends View { private final Paint blockPaint = new Paint(Paint.ANTI_ALIAS_FLAG); private final Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG); - private static final int BLOCK_START_X = 15; - private static final int BLOCK_START_Y = 15; - private static final int NORMAL_TEXT_MARGIN_LEFT = 40; - private static final int NORMAL_TEXT_MARGIN_RIGHT = 50; - private static final int SHORT_TEXT_MARGIN_LEFT = 60; - private static final int SHORT_TEXT_MARGIN_RIGHT = 70; + private static int textSize = 40; + private static int BLOCK_START_X = 15; + private static int BLOCK_START_Y = 15; + private static int NORMAL_TEXT_MARGIN_LEFT = 40; + private static int NORMAL_TEXT_MARGIN_RIGHT = 60; + private static int SHORT_TEXT_MARGIN_LEFT = 60; + private static int SHORT_TEXT_MARGIN_RIGHT = 70; private int textMarginLeft = NORMAL_TEXT_MARGIN_LEFT; private int textMarginRight = NORMAL_TEXT_MARGIN_RIGHT; @@ -107,7 +117,7 @@ public class SlidePanelView extends View { bgPaint.setStyle(Paint.Style.FILL); textPaint.setStyle(Paint.Style.FILL); - textPaint.setTextSize(40); + textPaint.setTextSize(textSize); textPaint.setTextAlign(Paint.Align.LEFT); textGradient = new LinearGradient(-GRADIENT_OFFSET, 0, 0, 0, new int[]{0x33ffffff, 0xffffffff, 0x33ffffff}, null, Shader.TileMode.CLAMP); textGradient.setLocalMatrix(gradientMatrix); diff --git a/OCH/mogo-och/src/main/res/layout/module_mogo_och_base_fragment.xml b/OCH/mogo-och/src/main/res/layout/module_mogo_och_base_fragment.xml index cc4d7ee2cb..8e31eb693a 100644 --- a/OCH/mogo-och/src/main/res/layout/module_mogo_och_base_fragment.xml +++ b/OCH/mogo-och/src/main/res/layout/module_mogo_och_base_fragment.xml @@ -58,10 +58,17 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone" - tools:visibility="visible" + app:BLOCK_START_X="@dimen/module_mogo_och_slide_panel_block_start_x" + app:BLOCK_START_Y="@dimen/module_mogo_och_slide_panel_block_start_y" + app:NORMAL_TEXT_MARGIN_LEFT="@dimen/module_mogo_och_slide_panel_normal_text_margin_left" + app:NORMAL_TEXT_MARGIN_RIGHT="@dimen/module_mogo_och_slide_panel_normal_text_margin_right" + app:SHORT_TEXT_MARGIN_LEFT="@dimen/module_mogo_och_slide_panel_short_text_margin_left" + app:SHORT_TEXT_MARGIN_RIGHT="@dimen/module_mogo_och_slide_panel_short_text_margin_right" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" - app:layout_constraintRight_toRightOf="parent" /> + app:layout_constraintRight_toRightOf="parent" + app:textSize="@dimen/module_mogo_och_slide_panel_textSize" + tools:visibility="visible" />