android画虚线后是实线
2016-04-19 15:58
363 查看
android4.0之后就默认开启硬件加速,用drawable文件写虚线在4.0之后就不会显示。
解决方法是我们可以关闭android的硬件加速.
Application级别:<applicationandroid:hardwareAccelerated="true" ...>
Activity级别:<activity android:hardwareAccelerated="false" ...>
Window级别:
注意:目前为止,Android还不支持在Window级别关闭硬件加速。
View级别:
其实是还可以在xml文件里面关闭硬件加速,这是我目前觉得算好的方法。
android:layerType="software"
最好的方法就是自定义一个view。
解决方法是我们可以关闭android的硬件加速.
Application级别:<applicationandroid:hardwareAccelerated="true" ...>
Activity级别:<activity android:hardwareAccelerated="false" ...>
Window级别:
getWindow().setFlags( WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
注意:目前为止,Android还不支持在Window级别关闭硬件加速。
View级别:
myView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
其实是还可以在xml文件里面关闭硬件加速,这是我目前觉得算好的方法。
android:layerType="software"
最好的方法就是自定义一个view。
import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.DashPathEffect; import android.graphics.Paint; import android.graphics.Path; import android.graphics.PathEffect; import android.util.AttributeSet; import android.view.View; import com.zy.haoyikang_consumers.R; /** * 虚线view * Created by deng on 16/4/18. */ public class DashLineView extends View { private final int HORIZONTAL = 0, VERTICAL = 1; private int mOrientation = 1; private int mDashColor = Color.BLACK; private int mDashWidth = 10; private int mWidth = 10; public DashLineView(Context context) { this(context, null); } public DashLineView(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.DashLineView, 0, 0); mOrientation = a.getInt(R.styleable.DashLineView_dlv_orientation, mOrientation); mDashColor = a.getColor(R.styleable.DashLineView_dlv_dashColor, mDashColor); mDashWidth = a.getDimensionPixelSize(R.styleable.DashLineView_dlv_dashWidth, mDashWidth); mWidth = a.getDimensionPixelSize(R.styleable.DashLineView_dlv_width, mWidth); a.recycle(); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); Paint paint = new Paint(); paint.setStyle(Paint.Style.STROKE); paint.setColor(mDashColor); paint.setStrokeWidth(mWidth); // // PathEffect effects = new DashPathEffect(new float[]{mDashWidth, mDashWidth, mDashWidth, mDashWidth}, 1); // paint.setPathEffect(effects); // // if(HORIZONTAL == mOrientation) // canvas.drawLine(0,0,getWidth(),0,paint); // else canvas.drawLine(0,0,0,getHeight(),paint); Path path = new Path(); if(mOrientation == HORIZONTAL){ path.moveTo(0, 0); path.lineTo(getWidth(),0); }else{ path.moveTo(0,0); path.lineTo(0,getHeight()); } PathEffect effects = new DashPathEffect(new float[]{mDashWidth,mDashWidth,mDashWidth,mDashWidth},1); paint.setPathEffect(effects); canvas.drawPath(path, paint); } }
相关文章推荐
- Android签名打包报错
- Android平台,利用zxing库开发扫码功能
- [置顶] Android开发之设置应用设置全屏的两种解决方法 兼容android5.0等两种解决方法
- Android练习项目 Mp3播放器实现(二)
- Android 环境下编译FFmpeg
- 【Android】输入框控件EditText
- android加载大量图片内存溢出的三种解决办法
- Android中判断SD卡状态
- Android访问WEBAPI,传递json
- Android studio 百度地图开发(7)overlayManager、overlayutil应用
- Android Studio制作library(图解)
- Android中启动第三方程序的代码
- android 菜单
- android 动态设置listview gridview高度
- Android 悬浮视图
- android 关于全局变量的使用
- Android获取系统相关的信息
- Android 子activity关闭 向父activity传值
- Android App中实现图片异步加载的实例分享
- Android-Xml绘图