java view_Java ViewStructure类代码示例

import android.view.ViewStructure; //导入依赖的package包/类

@TargetApi(Build.VERSION_CODES.M)

private void createVirtualStructure(ViewStructure viewNode, AccessibilitySnapshotNode node,

final boolean ignoreScrollOffset) {

viewNode.setClassName(node.className);

if (node.hasSelection) {

viewNode.setText(node.text, node.startSelection, node.endSelection);

} else {

viewNode.setText(node.text);

}

int left = (int) mRenderCoordinates.fromLocalCssToPix(node.x);

int top = (int) mRenderCoordinates.fromLocalCssToPix(node.y);

int width = (int) mRenderCoordinates.fromLocalCssToPix(node.width);

int height = (int) mRenderCoordinates.fromLocalCssToPix(node.height);

Rect boundsInParent = new Rect(left, top, left + width, top + height);

if (node.isRootNode) {

// Offset of the web content relative to the View.

boundsInParent.offset(0, (int) mRenderCoordinates.getContentOffsetYPix());

if (!ignoreScrollOffset) {

boundsInParent.offset(-(int) mRenderCoordinates.getScrollXPix(),

-(int) mRenderCoordinates.getScrollYPix());

}

}

viewNode.setDimens(boundsInParent.left, boundsInParent.top, 0, 0, width, height);

viewNode.setChildCount(node.children.size());

if (node.hasStyle) {

// The text size should be in physical pixels, not CSS pixels.

float textSize = mRenderCoordinates.fromLocalCssToPix(node.textSize);

int style = (node.bold ? ViewNode.TEXT_STYLE_BOLD : 0)

| (node.italic ? ViewNode.TEXT_STYLE_ITALIC : 0)

| (node.underline ? ViewNode.TEXT_STYLE_UNDERLINE : 0)

| (node.lineThrough ? ViewNode.TEXT_STYLE_STRIKE_THRU : 0);

viewNode.setTextStyle(textSize, node.color, node.bgcolor, style);

}

for (int i = 0; i < node.children.size(); i++) {

createVirtualStructure(viewNode.asyncNewChild(i), node.children.get(i), true);

}

viewNode.asyncCommit();

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值