整个观对角线 [英] Diagonal line across view

查看:210
本文介绍了整个观对角线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据一些条件,我要切成斜列表单元格。对于这个我已经使用这个code对角线绘制的图像:

Based on some condition, I have to diagonally cut the list cell. For this I have made diagonal drawable image using this code:

diagonal_line.xml

 <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:top="0dp"
        android:bottom="0dp"
        >
        <rotate
            android:fromDegrees="315"
            android:toDegrees="315"
            android:pivotX="0%"
            android:pivotY="0%" >
            <shape
                android:shape="line"
                >
                <stroke
                    android:width="10dp"
                    android:color="@color/grey" />
            </shape>
        </rotate>
    </item>
    </layer-list>

在列表单元格的XML它被用作:

In list cell's xml it is used as:

 <ImageView 
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:background="@drawable/diagonal_line"
    android:layerType="software"
    android:scaleType="fitXY"
    />

这对角线出现在单元格的XML的图形视图,但是没有列表充气后。现在它的visbility是独立于任何条件,即它是知名度始终是真实的。

This diagonal line appears in graphics view of cell's xml but not after list is inflated. For now its visbility is independent of any condition i.e. it is visibility is always true.

任何想法,问题是什么?

Any idea where the issue is?

推荐答案

有关对角线自定义的看法是:

Custom view for diagonal line is:

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
public class DiagonalLineView extends View {

private int dividerColor;
private Paint paint;

public DiagonalLineView(Context context)
{
    super(context);
    init(context);
}

public DiagonalLineView(Context context, AttributeSet attrs)
{
    super(context, attrs);
    init(context);
}

public DiagonalLineView(Context context, AttributeSet attrs, int defStyle)
{
    super(context, attrs, defStyle);
    init(context);
}

private void init(Context context)
{
    Resources resources = context.getResources();
    dividerColor = resources.getColor(R.color.grey);

    paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColor(dividerColor);
         paint.setStrokeWidth(resources.getDimension(R.dimen.vertical_divider_width));
}

@Override
protected void onDraw(Canvas canvas)
{
    super.onDraw(canvas);
    canvas.drawLine(0, getHeight(), getWidth(), 0, paint);
}

}

这为我工作。

这篇关于整个观对角线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆