• 界面布局自定义Layout, 边框shape文件, 按钮selector文件及用法


    package com.lonshin.chexiaodi.utils;
    
    import android.content.Context;
    import android.util.AttributeSet;
    import android.util.Log;
    import android.view.MotionEvent;
    import android.view.View;
    import android.view.View.OnTouchListener;
    import android.widget.RelativeLayout;
    
    import com.krislq.sliding.R;
    
    public class ClickableCornerLayout extends RelativeLayout implements OnTouchListener  {
        
        public ClickableCornerLayout(Context context) {
            super(context);
        }
    
        public ClickableCornerLayout(Context context, AttributeSet attrs) {
            super(context, attrs);
            this.setBackgroundResource(R.drawable.table_style);//这里也可以set成ARGB颜色
            setOnTouchListener(this);
            setClickable(true);
            
        }
        
        public ClickableCornerLayout(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
            this.setBackgroundResource(R.drawable.table_style);
            setOnTouchListener(this);
            setClickable(true);
        }
    
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                this.setBackgroundResource(R.drawable.table_style_dedede);
            } else if (event.getAction() == MotionEvent.ACTION_UP) {
                this.setBackgroundResource(R.drawable.table_style);
            }
            return false;
        }
    }

    可如上自定义一个Layout.

    想让一个widget圆角等,可定义一个shape文件,然后再设置background="@drawable/xxxxxx"

    shape文件需要以下几个内容:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <corners android:radius="6.0dp"/>
        <solid android:color="#ffffff"/>
        <stroke
            android:width="1dp"
            android:color="#cccccc"/>
    </shape>

    按钮需要selector文件,同样需要backround="@drawable/xxxx"

    <?xml version="1.0" encoding="UTF-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
         <item android:state_pressed="true"
               android:drawable="@drawable/btn_call_s_hit" /> <!-- pressed -->
         <item android:state_focused="true"
               android:drawable="@drawable/btn_call_s" /> <!-- focused -->
         <item android:drawable="@drawable/btn_call_s" /> <!-- default -->
     </selector>
  • 相关阅读:
    士兵队列训练问题http://acm.hdu.edu.cn/showproblem.php?pid=1276
    Fence Repair http://poj.org/problem?id=3253
    A/B http://acm.hdu.edu.cn/showproblem.php?pid=1576
    房间安排http://acm.nyist.net/JudgeOnline/problem.php?pid=168
    Function Run Fun http://poj.org/problem?id=1579
    盗梦空间http://acm.nyist.net/JudgeOnline/problem.php?pid=125
    如何在Chrome中使用”并非来自Chrome网上应用店”的扩展程序
    C++中的函数指针模板
    C/C++中的源文件与头文件的区别
    C++同名函数的各种问题
  • 原文地址:https://www.cnblogs.com/linxiaojiang/p/2993737.html
Copyright © 2020-2023  润新知