android--XML中画横线、竖线和虚线

一、画横线

<View
     android:layout_width="match_parent"
     android:layout_height="@dimen/border_line"
     android:background="#000000" />


二、画竖线

<View
     android:layout_width="1dp"
     android:layout_height="match_parent"
     android:background="#000000" />


三、画虚线
在drawable中新建一个dash_line.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line">
<stroke
    android:color="#000000"
    android:dashWidth="3dp"
    android:dashGap="5dp"/>
    <!--width:线条的高度
    color:颜色
    dashWidth:破折线的宽度
    dashGap:破折线间空隙的宽度
    如果这里设置了width,xml中android:layout_height的值必须比它大。不设置就默认为0
    -->
</shape>


在布局文件中使用
 

<View
     android:layout_width="match_parent"
     android:layout_height="2dp"
     android:layerType="software"
     android:background="@drawable/dash_line"/>

四、android控件drawableLeft图片大小控制

private void setDrawLeft(EditText editText,int res){
        Drawable drawable = getResources().getDrawable(res);
        drawable.setBounds(0,0,100,100);
        editText.setCompoundDrawables(drawable,null,null,null);
    }
setBounds(x,y,width,height); x:组件在容器X轴上的起点 y:组件在容器Y轴上的起点 width:组件的长度 height
  • 7
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在指定时间内匀速一条直线,您可以使用ValueAnimator来实现。首先,您需要自定义一个View,重写onDraw方法,在该方法内绘制一条直线。然后,您需要在View的构造函数中创建一个ValueAnimator对象,并设置它的属性动为“fraction”,时长为您想要的时间。在动更新过程中,您需要计算直线的起点和终点坐标,并调用invalidate方法不断绘制直线。下面是一个示例代码: ``` public class LineView extends View { private Paint paint; private float startX; private float startY; private float endX; private float endY; private ValueAnimator animator; public LineView(Context context) { this(context, null); } public LineView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public LineView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); } private void init() { paint = new Paint(); paint.setColor(Color.BLACK); paint.setStrokeWidth(5); // 创建ValueAnimator对象,时长为3000ms animator = ValueAnimator.ofFloat(0f, 1f).setDuration(3000); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { // 计算直线的起点和终点坐标 float fraction = (float) animation.getAnimatedValue(); startX = 0; startY = getHeight() / 2; endX = getWidth() * fraction; endY = getHeight() / 2; // 调用invalidate方法,不断绘制直线 invalidate(); } }); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawLine(startX, startY, endX, endY, paint); } public void startAnimation() { animator.start(); } } ``` 在上面的代码中,我们首先在init方法中创建了一个ValueAnimator对象,并设置它的属性动为“fraction”,时长为3000ms。在动更新过程中,我们计算了直线的起点和终点坐标,并调用invalidate方法,不断绘制直线。在startAnimation方法中,我们启动了ValueAnimator动。您可以在您的Activity或Fragment中调用该方法,启动动

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值