Android 自定義 View - AreaSelectLayout

前幾天寫了一個(gè)小工具,其中一個(gè)設(shè)置項(xiàng)需要屏幕區(qū)域范圍坐標(biāo)參數(shù)斋陪,由于通過(guò)觀察直接填寫坐標(biāo)信息不太現(xiàn)實(shí)癌淮,于是就有了通過(guò)直接拖拽屏幕去取這個(gè)參數(shù)的需求,又因?yàn)樾枰谌我饨缑娑寄苓x取舔箭,所以就想到了懸浮窗,這里以前寫過(guò)一個(gè)懸浮窗工具類《FloatWindowUtils 實(shí)現(xiàn)及事件沖突解決詳解》蚊逢,想著再加一些手勢(shì)及繪制應(yīng)該就能實(shí)現(xiàn)层扶,于是吭嘰吭嘰搞了半天,發(fā)現(xiàn)其中還是有些坑的烙荷,所以在此記錄備忘镜会。

效果圖和用法如下:

未命名.gif

如上圖,這個(gè) View 的功能很簡(jiǎn)單终抽,就是在屏幕上彈出一個(gè)全屏懸浮窗遮罩戳表,然后在上面拖拽選擇區(qū)域焰薄,最后保存坐標(biāo)信息就好了。

詳細(xì)實(shí)現(xiàn)我就不講了扒袖,后面會(huì)貼源碼塞茅,這里主要講一下實(shí)現(xiàn)思路和幾個(gè)需要注意的點(diǎn)

實(shí)現(xiàn)思路

繼承 View 還是 ViewGroup

由于懸浮窗里需要有提示文字以及取消和保存兩個(gè)按鈕,所以我沒(méi)有直接去繼承 View 來(lái)寫季率,直接繼承 View 來(lái)實(shí)現(xiàn)當(dāng)然也可以野瘦,但是需要把下面的文字以及按鈕都畫出來(lái),可能還需要內(nèi)置按鈕的觸發(fā)回調(diào)等等業(yè)務(wù)飒泻,最終我選擇了繼承 ViewGroup(ConstrainsLayout) 來(lái)實(shí)現(xiàn)鞭光,這樣做可以共享 ConstrainsLayout 的所有屬性。和直接繼承 View 實(shí)現(xiàn)相比泞遗,它的優(yōu)點(diǎn)就是可以在布局文件中方便的添加子 View惰许,缺點(diǎn)是集成度不夠高,需要引用外部資源史辙,所以具體實(shí)現(xiàn)可以看使用場(chǎng)景汹买,這里沒(méi)有復(fù)用的場(chǎng)景,集成度要求不高聊倔,所以就選擇了更簡(jiǎn)單的繼承 ViewGroup 來(lái)實(shí)現(xiàn)晦毙。

class AreaSelectLayout : ConstraintLayout {
    constructor(context: Context) : super(context) {}
    constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {}
    
    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
    }

    @SuppressLint("ClickableViewAccessibility")
    override fun onTouchEvent(event: MotionEvent): Boolean {
        return super.onTouchEvent(event)
    }
}
<?xml version="1.0" encoding="utf-8"?>
<com.example.area_select_layout.AreaSelectLayout
    ...
    android:background="@color/half_trans">

    <ImageButton
        android:id="@+id/btn_save"
        ... />

    <ImageButton
        android:id="@+id/btn_cancel"
        ... />

    <LinearLayout ...>
        <TextView
            android:id="@+id/textView4"
            android:text="拖動(dòng)選取"
            ... />

        <TextView
            android:id="@+id/textView5"
            android:text="起始"
            ... />

        <TextView
            android:text="和"
            ... />

        <TextView
            android:text="結(jié)束"
            ... />

        <TextView
            android:text="區(qū)域"
            ... />
    </LinearLayout>

</com.example.area_select_layout.AreaSelectLayout>
跟隨手指移動(dòng)繪制方框

區(qū)域選擇,其實(shí)就是在屏幕上畫對(duì)角線耙蔑,手指落下见妒,記錄起點(diǎn),手指移動(dòng)甸陌,不斷更新終點(diǎn)并通知 Canvas 畫出來(lái)须揣,手指抬起,保存最終坐標(biāo)钱豁。這里需要注意的是 Y 坐標(biāo)要減去 StatusBar 的高度耻卡。

@SuppressLint("ClickableViewAccessibility")
override fun onTouchEvent(event: MotionEvent): Boolean {
    when (event.action) {
        MotionEvent.ACTION_DOWN -> {
            // 記錄起點(diǎn)位置
            setStartPos(event.rawX.toInt(), (event.rawY - statusBarHeight).toInt())
        }
        MotionEvent.ACTION_MOVE -> {
            // 更新終點(diǎn)位置
            setStopPos(event.rawX.toInt(), (event.rawY - statusBarHeight).toInt())
            // 使布局失效,讓系統(tǒng)觸發(fā) onDraw 重繪界面
            invalidate()
        }
    }
    return super.onTouchEvent(event)
}
位置存儲(chǔ)以及方向判斷

由于位置總共有四個(gè)點(diǎn)寥院,八個(gè)坐標(biāo)值劲赠,用變量來(lái)存很不便涛目,所以我直接用 Rect 來(lái)存了秸谢,一是便于管理,可以用這些值方便的判斷正在選區(qū)起始區(qū)域或是結(jié)束區(qū)域霹肝,二是可以直接通過(guò) Canvas.drawRect(Rect, Paint) 來(lái)繪制方框了估蹄。

private fun setStartPos(rawX: Int, rawY: Int) {
    // 起始區(qū)域已經(jīng)繪制
    if (startRect.bottom != 0) {
        startSelected = true
    }
    // 如果存在兩個(gè)選區(qū)的話,則清屏重繪制
    if (startRect.bottom != 0 && endRect.bottom != 0) {
        clear()
    }
    // 判斷落點(diǎn)屬于起始區(qū)域還是結(jié)束區(qū)域
    if (startSelected) {
        end.x = rawX
        end.y = rawY
    } else {
        start.x = rawX
        start.y = rawY
    }
}
private fun setStopPos(rawX: Int, rawY: Int) {
    // 判斷終點(diǎn)屬于起始區(qū)域還是結(jié)束區(qū)域
    if (startSelected) {
        // rawX < end.x 表示從左向右拖動(dòng) ?
        // ? 時(shí) x 更新 right沫换,y 同理
        endRect.left = if (rawX < end.x) rawX else end.x
        // rawX > end.x 表示從右向左拖動(dòng) ?
        // ? 時(shí) x 更新 left臭蚁,y 同理
        endRect.right = if (rawX > end.x) rawX else end.x
        endRect.top = if (rawY < end.y) rawY else end.y
        endRect.bottom = if (rawY > end.y) rawY else end.y
    } else {
        startRect.left = if (rawX < start.x) rawX else start.x
        startRect.right = if (rawX > start.x) rawX else start.x
        startRect.top = if (rawY < start.y) rawY else start.y
        startRect.bottom = if (rawY > start.y) rawY else start.y
    }
}
使布局懸浮在應(yīng)用之外

這塊考慮了一下,最后還是沒(méi)有用 FloatWindowUtils,因?yàn)榫鸵粋€(gè)布局垮兑,了解了懸浮窗怎么玩之后冷尉,懸浮起一個(gè)布局也很簡(jiǎn)單,直接用 WindowManager 十幾行代碼搞定了系枪。

private fun showSelectLayout() {
    if (!SystemSetings.isAppOpsOn(this)) {
        SystemSetings.openOpsSettings(this)
        Toast.makeText(this,"請(qǐng)先開(kāi)啟懸浮窗權(quán)限",Toast.LENGTH_SHORT).show()
        return
    }
    wm = getSystemService(Context.WINDOW_SERVICE) as WindowManager
    val lp = WindowManager.LayoutParams()
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        lp.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
    } else {
        lp.type = WindowManager.LayoutParams.TYPE_PHONE
    }
    lp.format = PixelFormat.TRANSLUCENT
    lp.flags = lp.flags or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
    lp.width = WindowManager.LayoutParams.MATCH_PARENT
    lp.height = WindowManager.LayoutParams.MATCH_PARENT
    lp.gravity = Gravity.END or Gravity.TOP
    if (selectLayout.parent!=null){
        wm.removeView(selectLayout)
    }
    wm.addView(selectLayout, lp)
}

核心部分基本就是上面這些了雀哨,算位置的時(shí)候稍微有點(diǎn)繞但是不難,多分析下就出來(lái)了私爷,下面貼下源碼

項(xiàng)目源碼

manifests.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.area_select_layout">
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>
MainActivity.kt
class MainActivity : AppCompatActivity() {
    private lateinit var selectLayout: AreaSelectLayout
    private lateinit var btnSave: View
    private lateinit var btnCancel: View
    private lateinit var wm: WindowManager
    @SuppressLint("SetTextI18n")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        selectLayout = View.inflate(this,R.layout.dialog_select_layout,null) as AreaSelectLay
        btnSave = selectLayout.findViewById(R.id.btn_save)
        btnCancel = selectLayout.findViewById(R.id.btn_cancel)
        btnSave.setOnClickListener {
            hideSelectLayout()
            val startRect = selectLayout.getStartRect()
            val endRect = selectLayout.getEndRect()
            textView.text = "start-area:[${startRect.left},${startRect.top}]," +
                    "[${startRect.right},${startRect.bottom}]" +
                    "\n" +
                    "end-area:[${endRect.left},${endRect.top}]," +
                    "[${endRect.right},${endRect.bottom}]"
        }
        btnCancel.setOnClickListener {
            hideSelectLayout()
            selectLayout.clear()
        }
        button.setOnClickListener {
            showSelectLayout()
        }
    }
    private fun hideSelectLayout() {
        wm.removeView(selectLayout)
    }
    private fun showSelectLayout() {
        if (!SystemSetings.isAppOpsOn(this)) {
            SystemSetings.openOpsSettings(this)
            Toast.makeText(this,"請(qǐng)先開(kāi)啟懸浮窗權(quán)限",Toast.LENGTH_SHORT).show()
            return
        }
        // 設(shè)置位置
        wm = getSystemService(Context.WINDOW_SERVICE) as WindowManager
        val lp = WindowManager.LayoutParams()
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            lp.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
        } else {
            lp.type = WindowManager.LayoutParams.TYPE_PHONE
        }
        lp.format = PixelFormat.TRANSLUCENT
        lp.flags = lp.flags or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
        lp.width = WindowManager.LayoutParams.MATCH_PARENT
        lp.height = WindowManager.LayoutParams.MATCH_PARENT
        lp.gravity = Gravity.END or Gravity.TOP
        if (selectLayout.parent!=null){
            wm.removeView(selectLayout)
        }
        wm.addView(selectLayout, lp)
    }
}
AreaSelectLayout.kt
class AreaSelectLayout : ConstraintLayout {
    private var paint = Paint(Paint.ANTI_ALIAS_FLAG)
    private var endPaint = Paint(Paint.ANTI_ALIAS_FLAG)
    private var paintText = Paint(Paint.ANTI_ALIAS_FLAG)
    /**
     * 滑動(dòng)范圍
     */
    private var startRect = Rect()
    private var endRect = Rect()
    /**
     * 坐標(biāo)文字邊框
     */
    private var ltStrBounds = Rect()
    private var rbStrBounds = Rect()
    private var start = Point()
    private var end = Point()
    private var startSelected = false
    private val statusBarHeight: Int
        get() {
            val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android")
            return resources.getDimensionPixelSize(resourceId)
        }
    constructor(context: Context) : super(context) {}
    constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {}
    init {
        paint.strokeWidth = dp2px(2f)
        paint.style = Paint.Style.STROKE
        paint.color = Color.parseColor("#1aad19")
        endPaint.strokeWidth = dp2px(2f)
        endPaint.style = Paint.Style.STROKE
        endPaint.color = Color.parseColor("#f45454")
        paintText.textSize = dp2px(12f)
        paintText.color = Color.parseColor("#1aad19")
    }
    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        // 繪制結(jié)束區(qū)域
        canvas.drawRect(endRect, endPaint)
        // 繪制起始區(qū)域
        canvas.drawRect(startRect, paint)
    }
    @SuppressLint("ClickableViewAccessibility")
    override fun onTouchEvent(event: MotionEvent): Boolean {
        when (event.action) {
            MotionEvent.ACTION_DOWN -> {
                setStartPos(event.rawX.toInt(), (event.rawY - statusBarHeight).toInt())
            }
            MotionEvent.ACTION_MOVE -> {
                setStopPos(event.rawX.toInt(), (event.rawY - statusBarHeight).toInt())
                invalidate()
            }
        }
        return super.onTouchEvent(event)
    }
    private fun setStartPos(rawX: Int, rawY: Int) {
        if (startRect.bottom != 0) {
            startSelected = true
        }
        if (startRect.bottom != 0 && endRect.bottom != 0) {
            clear()
        }
        if (startSelected) {
            end.x = rawX
            end.y = rawY
        } else {
            start.x = rawX
            start.y = rawY
        }
    }
    private fun setStopPos(rawX: Int, rawY: Int) {
        if (startSelected) {
            endRect.left = if (rawX < end.x) rawX else end.x
            endRect.right = if (rawX > end.x) rawX else end.x
            endRect.top = if (rawY < end.y) rawY else end.y
            endRect.bottom = if (rawY > end.y) rawY else end.y
        } else {
            startRect.left = if (rawX < start.x) rawX else start.x
            startRect.right = if (rawX > start.x) rawX else start.x
            startRect.top = if (rawY < start.y) rawY else start.y
            startRect.bottom = if (rawY > start.y) rawY else start.y
        }
    }
    fun clear() {
        startSelected = false
        startRect.top = 0
        startRect.bottom = 0
        startRect.left = 0
        startRect.right = 0
        endRect.top = 0
        endRect.bottom = 0
        endRect.left = 0
        endRect.right = 0
        invalidate()
    }
    fun setStartRect(rect: Rect) {
        this.startRect = rect
    }
    fun getStartRect(): Rect {
//        val rstRect = startRect
//        rstRect.top += statusBarHeight
//        rstRect.bottom += statusBarHeight
        return startRect
    }
    fun setEndRect(rect: Rect) {
        this.endRect = rect
    }
    fun getEndRect(): Rect {
//        val rstRect = endRect
//        rstRect.top += statusBarHeight
//        rstRect.bottom += statusBarHeight
        return endRect
    }
    fun dp2px(dp: Float): Float {
        return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, Resources.getSystem().displayMetrics)
    }
}
SystemSetings.kt
/**
 * Created by skyrin on 2016/9/25.
 * 系統(tǒng)設(shè)置相關(guān)
 */
object SystemSetings {
    /**
     * 輔助服務(wù)是否開(kāi)啟
     * @param context
     * @return true if Accessibility is on.
     */
    fun isAccessibilitySettingsOn(context: Context): Boolean {
        var i: Int
        try {
            i = Settings.Secure.getInt(context.contentResolver, "accessibility_enabled")
        } catch (e: Settings.SettingNotFoundException) {
            Log.i("AccessibilitySettingsOn", e.message)
            i = 0
        }
        if (i != 1) {
            return false
        }
        val string = Settings.Secure.getString(context.contentResolver, "enabled_accessibility_services")
        return string?.toLowerCase()?.contains(context.packageName.toLowerCase()) ?: false
    }
    /**
     * 打開(kāi)輔助服務(wù)的設(shè)置
     */
    fun openAccessibilityServiceSettings(context: Context): Boolean {
        var result = true
        try {
            val intent = Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            context.startActivity(intent)
        } catch (e: Exception) {
            result = false
            e.printStackTrace()
        }
        return result
    }
    /** 打開(kāi)通知欄設(shè)置 */
    @TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
    fun openNotificationServiceSettings(context: Context) {
        try {
            val intent = Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS)
            context.startActivity(intent)
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }
    /**
     * 打開(kāi)app權(quán)限的設(shè)置
     * @param context
     * @return
     */
    fun openFloatWindowSettings(context: Context): Boolean {
        try {
            val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
            val uri = Uri.fromParts("package", context.packageName, null)
            intent.data = uri
            context.startActivity(intent)
        } catch (e: Exception) {
            e.printStackTrace()
            return false
        }
        return true
    }
    /**
     * 打開(kāi)app權(quán)限的設(shè)置
     * @param context
     * @return
     */
    fun openFloatWindowSettings(context: Context, pkgName: String): Boolean {
        try {
            val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
            val uri = Uri.fromParts("package", pkgName, null)
            intent.data = uri
            context.startActivity(intent)
        } catch (e: Exception) {
            e.printStackTrace()
            return false
        }
        return true
    }
    /**
     * 打開(kāi)懸浮窗設(shè)置頁(yè)
     * 部分第三方ROM無(wú)法直接跳轉(zhuǎn)可使用[.openAppSettings]跳到應(yīng)用詳情頁(yè)
     *
     * @param context
     * @return true if it's open successful.
     */
    fun openOpsSettings(context: Context): Boolean {
        try {
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
                val intent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + context.packageName))
                context.startActivity(intent)
            } else {
                return openAppSettings(context)
            }
        } catch (e: Exception) {
            e.printStackTrace()
            return false
        }
        return true
    }
    /**
     * 打開(kāi)應(yīng)用詳情頁(yè)
     *
     * @param context
     * @return true if it's open success.
     */
    fun openAppSettings(context: Context): Boolean {
        try {
            val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
            val uri = Uri.fromParts("package", context.packageName, null)
            intent.data = uri
            context.startActivity(intent)
        } catch (e: Exception) {
            e.printStackTrace()
            return false
        }
        return true
    }
    /**
     * 判斷 懸浮窗口權(quán)限是否打開(kāi)
     * 由于android未提供直接跳轉(zhuǎn)到懸浮窗設(shè)置頁(yè)的api雾棺,此方法使用反射去查找相關(guān)函數(shù)進(jìn)行跳轉(zhuǎn)
     * 部分第三方ROM可能不適用
     *
     * @param context
     * @return true 允許  false禁止
     */
    fun isAppOpsOn(context: Context): Boolean {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            return Settings.canDrawOverlays(context)
        }
        try {
            val `object` = context.getSystemService(Context.APP_OPS_SERVICE) ?: return false
            val localClass = `object`.javaClass
            val arrayOfClass = arrayOfNulls<Class<*>>(3)
            arrayOfClass[0] = Integer.TYPE
            arrayOfClass[1] = Integer.TYPE
            arrayOfClass[2] = String::class.java
            val method = localClass.getMethod("checkOp", *arrayOfClass) ?: return false
            val arrayOfObject1 = arrayOfNulls<Any>(3)
            arrayOfObject1[0] = 24
            arrayOfObject1[1] = Binder.getCallingUid()
            arrayOfObject1[2] = context.packageName
            val m = method.invoke(`object`, *arrayOfObject1) as Int
            return m == AppOpsManager.MODE_ALLOWED
        } catch (ex: Exception) {
            ex.stackTrace
        }
        return false
    }
    /**
     * 啟動(dòng)app
     *
     * @param context
     * @param pkgName 包名
     * @return 是否啟動(dòng)成功
     */
    fun startApp(context: Context, pkgName: String): Boolean {
        try {
            val manager = context.packageManager
            val openApp = manager.getLaunchIntentForPackage(pkgName) ?: return false
            openApp.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP
            context.startActivity(openApp)
        } catch (e: Exception) {
            return false
        }
        return true
    }
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="160dp"
        android:text="選擇區(qū)域"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.498"
        app:layout_constraintStart_toStartOf="parent" />
    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="80dp"
        android:text="TextView"
        app:layout_constraintBottom_toTopOf="@+id/button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>
dialog_select_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<com.example.area_select_layout.AreaSelectLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="@color/half_trans">
    <ImageButton
        android:id="@+id/btn_save"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:background="@null"
        android:src="@drawable/ic_ok"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent" />
    <ImageButton
        android:id="@+id/btn_cancel"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_marginBottom="0dp"
        android:background="@null"
        android:src="@drawable/ic_cancel"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent" />
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="0dp"
        android:layout_marginEnd="8dp"
        android:orientation="horizontal"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/btn_save">
        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="拖動(dòng)選取"
            android:textColor="@color/white"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toTopOf="@+id/btn_save"
            app:layout_constraintVertical_bias="0.448"
            tools:layout_editor_absoluteX="61dp" />
        <TextView
            android:id="@+id/textView5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="起始"
            android:textColor="#1aad19"
            tools:layout_editor_absoluteX="162dp"
            tools:layout_editor_absoluteY="476dp" />
        <TextView
            android:id="@+id/textView6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="和"
            android:textColor="@color/white"
            tools:layout_editor_absoluteX="209dp"
            tools:layout_editor_absoluteY="475dp" />
        <TextView
            android:id="@+id/textView7"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="結(jié)束"
            android:textColor="#f45454"
            tools:layout_editor_absoluteX="243dp"
            tools:layout_editor_absoluteY="474dp" />
        <TextView
            android:id="@+id/textView8"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="區(qū)域"
            android:textColor="@color/white"
            tools:layout_editor_absoluteX="276dp"
            tools:layout_editor_absoluteY="474dp" />
    </LinearLayout>
</com.example.area_select_layout.AreaSelectLayout>
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#008577</color>
    <color name="colorPrimaryDark">#00574B</color>
    <color name="colorAccent">#D81B60</color>
    <color name="red">#d02129</color>
    <color name="vip">#f5b53a</color>
    <color name="light_red">#ff620d</color>
    <color name="blue">#1189ff</color>
    <color name="blue_dark">#ff187998</color>
    <color name="white">#FFF</color>
    <color name="green">#ff1ce322</color>
    <color name="grey">#eeeffd</color>
    <color name="dark_gray">#525252</color>
    <color name="black">#000000</color>
    <color name="main">#09537a</color>
    <color name="main_trans">#991296db</color>
    <color name="full_trans">#00000000</color>
    <color name="no_trans">#00000001</color>
    <color name="half_trans">#80000000</color>
    <color name="status_bar">#09537a</color>
    <color name="df_layout">#fafafa</color>
    <color name="main_gray">#f5f5f5</color>
    <color name="waring">#ff620d</color>
    <color name="room_panel_bg">#80000000</color>
    <color name="sys_msg_bg">#b4b4b4</color>
    <color name="dialogue_msg">#3e3f3f</color>
    <color name="green0">#45C01A</color>
    <color name="green1">#45C01A</color>
    <color name="green2">#A3DEA3</color>
    <color name="green3">#1AAD19</color>
    <color name="ok">#1aad19</color>
    <color name="no">#ff620d</color>
    <color name="alpha_05_black">#0D000000</color>
    <color name="alpha_10_black">#1A000000</color>
    <color name="alpha_15_black">#26000000</color>
    <color name="alpha_20_black">#33000000</color>
    <color name="alpha_25_black">#40000000</color>
    <color name="alpha_30_black">#4D000000</color>
    <color name="alpha_33_black">#54000000</color>
    <color name="alpha_35_black">#59000000</color>
    <color name="alpha_40_black">#66000000</color>
    <color name="alpha_45_black">#73000000</color>
    <color name="alpha_50_black">#80000000</color>
    <color name="alpha_55_black">#8C000000</color>
    <color name="alpha_60_black">#99000000</color>
    <color name="alpha_65_black">#A6000000</color>
    <color name="alpha_70_black">#B3000000</color>
    <color name="alpha_75_black">#BF000000</color>
    <color name="alpha_80_black">#CC000000</color>
    <color name="alpha_85_black">#D9000000</color>
    <color name="alpha_90_black">#E6000000</color>
    <color name="alpha_95_black">#F2000000</color>
</resources>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市衬浑,隨后出現(xiàn)的幾起案子捌浩,更是在濱河造成了極大的恐慌,老刑警劉巖工秩,帶你破解...
    沈念sama閱讀 216,402評(píng)論 6 499
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件尸饺,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡助币,警方通過(guò)查閱死者的電腦和手機(jī)侵佃,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,377評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)奠支,“玉大人馋辈,你說(shuō)我怎么就攤上這事”睹眨” “怎么了迈螟?”我有些...
    開(kāi)封第一講書人閱讀 162,483評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)尔崔。 經(jīng)常有香客問(wèn)我答毫,道長(zhǎng),這世上最難降的妖魔是什么季春? 我笑而不...
    開(kāi)封第一講書人閱讀 58,165評(píng)論 1 292
  • 正文 為了忘掉前任洗搂,我火速辦了婚禮,結(jié)果婚禮上载弄,老公的妹妹穿的比我還像新娘耘拇。我一直安慰自己,他們只是感情好宇攻,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,176評(píng)論 6 388
  • 文/花漫 我一把揭開(kāi)白布惫叛。 她就那樣靜靜地躺著,像睡著了一般逞刷。 火紅的嫁衣襯著肌膚如雪嘉涌。 梳的紋絲不亂的頭發(fā)上妻熊,一...
    開(kāi)封第一講書人閱讀 51,146評(píng)論 1 297
  • 那天,我揣著相機(jī)與錄音仑最,去河邊找鬼扔役。 笑死,一個(gè)胖子當(dāng)著我的面吹牛警医,可吹牛的內(nèi)容都是我干的厅目。 我是一名探鬼主播,決...
    沈念sama閱讀 40,032評(píng)論 3 417
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼法严,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼损敷!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起深啤,我...
    開(kāi)封第一講書人閱讀 38,896評(píng)論 0 274
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤拗馒,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后溯街,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體诱桂,經(jīng)...
    沈念sama閱讀 45,311評(píng)論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,536評(píng)論 2 332
  • 正文 我和宋清朗相戀三年呈昔,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了挥等。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,696評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡堤尾,死狀恐怖肝劲,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情郭宝,我是刑警寧澤辞槐,帶...
    沈念sama閱讀 35,413評(píng)論 5 343
  • 正文 年R本政府宣布,位于F島的核電站粘室,受9級(jí)特大地震影響榄檬,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜衔统,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,008評(píng)論 3 325
  • 文/蒙蒙 一鹿榜、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧锦爵,春花似錦舱殿、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書人閱讀 31,659評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)刺彩。三九已至迷郑,卻和暖如春枝恋,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背嗡害。 一陣腳步聲響...
    開(kāi)封第一講書人閱讀 32,815評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工焚碌, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人霸妹。 一個(gè)月前我還...
    沈念sama閱讀 47,698評(píng)論 2 368
  • 正文 我出身青樓十电,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親叹螟。 傳聞我的和親對(duì)象是個(gè)殘疾皇子鹃骂,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,592評(píng)論 2 353

推薦閱讀更多精彩內(nèi)容