完成网约车的滑动View适配

This commit is contained in:
董宏宇
2021-05-13 13:20:45 +08:00
parent 288f9602d9
commit 4cd35941ac
5 changed files with 54 additions and 9 deletions

View File

@@ -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);

View File

@@ -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" />
<Button
android:id="@+id/btnAutopilotDisable"

View File

@@ -9,6 +9,14 @@
<dimen name="module_mogo_och_station_panel_container_margin_top_no_call">530px</dimen>
<dimen name="module_mogo_och_station_panel_container_margin_top_with_call">492px</dimen>
<dimen name="module_mogo_och_slide_panel_block_start_x">30px</dimen>
<dimen name="module_mogo_och_slide_panel_block_start_y">30px</dimen>
<dimen name="module_mogo_och_slide_panel_normal_text_margin_left">70px</dimen>
<dimen name="module_mogo_och_slide_panel_normal_text_margin_right">130px</dimen>
<dimen name="module_mogo_och_slide_panel_short_text_margin_left">93px</dimen>
<dimen name="module_mogo_och_slide_panel_short_text_margin_right">150px</dimen>
<dimen name="module_mogo_och_slide_panel_textSize">48px</dimen>
<dimen name="module_mogo_och_autopilot_status_bg_corner">24px</dimen>
<dimen name="module_mogo_och_autopilot_status_bg_width">460px</dimen>
<dimen name="module_mogo_och_autopilot_status_bg_height">140px</dimen>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="SlidePanelView">
<attr name="textSize" format="dimension" />
<attr name="NORMAL_TEXT_MARGIN_LEFT" format="dimension" />
<attr name="NORMAL_TEXT_MARGIN_RIGHT" format="dimension" />
<attr name="SHORT_TEXT_MARGIN_LEFT" format="dimension" />
<attr name="SHORT_TEXT_MARGIN_RIGHT" format="dimension" />
<attr name="BLOCK_START_X" format="dimension" />
<attr name="BLOCK_START_Y" format="dimension" />
</declare-styleable>
</resources>

View File

@@ -9,6 +9,14 @@
<dimen name="module_mogo_och_station_panel_container_margin_top_no_call">345px</dimen>
<dimen name="module_mogo_och_station_panel_container_margin_top_with_call">492px</dimen>
<dimen name="module_mogo_och_slide_panel_block_start_x">15px</dimen>
<dimen name="module_mogo_och_slide_panel_block_start_y">15px</dimen>
<dimen name="module_mogo_och_slide_panel_normal_text_margin_left">40px</dimen>
<dimen name="module_mogo_och_slide_panel_normal_text_margin_right">50px</dimen>
<dimen name="module_mogo_och_slide_panel_short_text_margin_left">50px</dimen>
<dimen name="module_mogo_och_slide_panel_short_text_margin_right">70px</dimen>
<dimen name="module_mogo_och_slide_panel_textSize">40px</dimen>
<dimen name="module_mogo_och_autopilot_status_bg_corner">24px</dimen>
<dimen name="module_mogo_och_autopilot_status_bg_width">300px</dimen>
<dimen name="module_mogo_och_autopilot_status_bg_height">100px</dimen>