展会信息港展会大全

模仿android自带切屏效果(屏幕切换)
来源:互联网   发布日期:2015-10-02 16:46:35   浏览:8732次  

导读:适用android平台所有版本吧。没有试过,只在2.2上试过。1.[图片] example.JPG2.[代码][Java]代码import java.util.ArrayList;import java.util.List;import android.content.Context;import android.graphi......

适用android平台所有版本吧。没有试过,只在2.2上试过。

1. [图片] example.JPG

2. [代码][Java]代码

import java.util.ArrayList;

import java.util.List;

import android.content.Context;

import android.graphics.Canvas;

import android.graphics.Region;

import android.util.Log;

import android.view.Gravity;

import android.view.MotionEvent;

import android.view.VelocityTracker;

import android.view.View;

import android.view.ViewConfiguration;

import android.view.ViewGroup;

import android.widget.GridView;

import android.widget.LinearLayout;

import android.widget.Scroller;

import com.huawei.R;

import com.huawei.constant.EnumLogClass;

import com.huawei.ui.maintab.bean.GroupModle;

import com.huawei.util.AndroidUtil;

import com.huawei.util.LogUtil;

public class MyTouchView extends ViewGroup {

public static final String TAG = "MyTouchView";

// constantooo

private static final int INVALID_SCREEN = -1;

private static final int SNAP_VELOCITY = 500;

private static final int TOUCH_STATE_REST = 0;

private static final int TOUCH_STATE_SCROLLING = 1;

// bg

// screen

private int mDefaultScreen;

// private boolean mFirstLayOut = true;

private int mCurrentScreen;

private int mNextScreen = INVALID_SCREEN;

private Scroller mScroller;

private int mScrollX;

private VelocityTracker mVelocityTracker;

private float mLastMotionX;

private int mTouchState = TOUCH_STATE_REST;

private int mTouchSlop;

private int mMaximumVelocity;

private OnGridItemClick itemClick;

private Context context;

private ViewmessagePanal;

public MyTouchView(Context context, String path) {

super(context);

this.context = context;

init(path);// init feature

}

// 初始化界面

private void init(String path) {

itemClick = new OnGridItemClick(context);

mCurrentScreen = mDefaultScreen;

mScroller = new Scroller(getContext());

final ViewConfiguration configuration = ViewConfiguration.get(context);

mTouchSlop = configuration.getScaledTouchSlop();

mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();

//---------------------------------------

LinearLayout temp = null;

List<GroupModle> list = ParseFromXmlToModle.getData(path);

createFromXmlToShowMessage(context);//showmessage

if (list != null && list.size() > 0) {

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

GroupModle grouptemp = list.get(i);

if (grouptemp != null) {

temp = new LinearLayout(context);

temp.setOrientation(LinearLayout.VERTICAL);

addView(temp);

if(messagePanal!=null){

temp.addView(messagePanal);

}

GridView gv = new GridView(context);

gv.setBackgroundResource(AndroidUtil.GetIDbyName(

grouptemp.icon, "drawable", context));

gv.setNumColumns(4);// 限定三列

//gv

//.setLayoutParams(new LayoutParams(

//LayoutParams.FILL_PARENT,

//LayoutParams.FILL_PARENT));

gv.setVerticalSpacing(10);

gv.setLayoutParams(new LinearLayout.LayoutParams(

LinearLayout.LayoutParams.FILL_PARENT,

LinearLayout.LayoutParams.FILL_PARENT,1

));

gv.setGravity(Gravity.CENTER_HORIZONTAL);

gv.setAdapter(new MyAdapter(context, grouptemp.childs));

gv.setOnItemClickListener(itemClick);

temp.addView(gv);

}

}

}

showDefaultScreen();

}

private void createFromXmlToShowMessage(Context context){

if(ParseFromXmlToModle.showable){

messagePanal=inflate(context,R.layout.common_message_show, null);

}

}

boolean isDefaultScreenShowing() {

return mCurrentScreen == mDefaultScreen;

}

int getCurrentScreen() {

return mCurrentScreen;

}

// set currentScrren

void setCurrentScreen(int currentScreen) {

if (!mScroller.isFinished()) {

mScroller.forceFinished(true);

}

clearChildrenCache();

mCurrentScreen = Math.max(0, Math.min(currentScreen,

getChildCount() - 1));

scrollTo(mCurrentScreen * getWidth(), 0);

getChildAt(getCurrentScreen()).requestFocus();

invalidate();

}

@Override

public void addFocusables(ArrayList<View> views, int direction) {

if (direction == View.FOCUS_LEFT) {

if (mCurrentScreen > 0) {

getChildAt(getCurrentScreen() - 1).addFocusables(views,

direction);

}

} else if (direction == View.FOCUS_RIGHT) {

if (mCurrentScreen < getChildCount() - 1) {

getChildAt(getCurrentScreen() + 1).addFocusables(views,

direction);

}

}

}

// clear cache;

void clearChildrenCache() {

final int count = getChildCount();

for (int i = 0; i < count; i++) {

final View child = getChildAt(i);

child.setDrawingCacheEnabled(false);

child.setDuplicateParentStateEnabled(false);

}

}

// enable cache;

void enableChildrenCache() {

final int count = getChildCount();

for (int i = 0; i < count; i++) {

final View child = getChildAt(i);

child.setDrawingCacheEnabled(true);

child.setDuplicateParentStateEnabled(true);

}

}

// show default screen

void showDefaultScreen() {

setCurrentScreen(mCurrentScreen);

}

// compute scroll how far

@Override

public void computeScroll() {

if (mScroller != null && mScroller.computeScrollOffset()) {

mScrollX = mScroller.getCurrX();

Log.i(TAG, "mScroller.getCurrX()=" + mScroller.getCurrX());

postInvalidate();

} else if (mNextScreen != INVALID_SCREEN) {

mCurrentScreen = Math.max(0, Math.min(mNextScreen,

getChildCount() - 1));

setCurrentScreen(getCurrentScreen());

mNextScreen = INVALID_SCREEN;

clearChildrenCache();

}

}

@Override

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

super.onMeasure(widthMeasureSpec, heightMeasureSpec);

final int width = MeasureSpec.getSize(widthMeasureSpec);

final int widthMode = MeasureSpec.getMode(widthMeasureSpec);

if (widthMode != MeasureSpec.EXACTLY) {

LogUtil.log(EnumLogClass.e, TAG, TAG+" can only be used inEXACTLY mode.");

}

final int height = MeasureSpec.getSize(widthMeasureSpec);

final int heightMode = MeasureSpec.getMode(heightMeasureSpec);

if (heightMode != MeasureSpec.EXACTLY) {

LogUtil.log(EnumLogClass.e, TAG, TAG+" can only be used inEXACTLY mode.");

}

final int count = getChildCount();

for (int i = 0; i < count; i++) {

getChildAt(i).measure(widthMeasureSpec, heightMeasureSpec);

}

// Log.i(TAG, "measure width=" + width);

// Log.i(TAG, "measure height=" + height);

// mWidth = width;

// mHeight = height;

// if (mFirstLayOut) {

// scrollTo(mCurrentScreen * width, 0);

// mFirstLayOut = false;

// }

}

@Override

protected void dispatchDraw(Canvas canvas) {

super.dispatchDraw(canvas);

canvas.clipRect(mScrollX, 0, mScrollX + getWidth(), getHeight(),

Region.Op.DIFFERENCE);

boolean fastDraw = mTouchState != TOUCH_STATE_SCROLLING

&& mNextScreen == INVALID_SCREEN;

if (fastDraw) {

drawChild(canvas, getChildAt(mCurrentScreen), getDrawingTime());

} else {

final long drawingTime = getDrawingTime();

if (mNextScreen >= 0 && mNextScreen < getChildCount()

&& Math.abs(mCurrentScreen - mNextScreen) == 1) {

drawChild(canvas, getChildAt(mCurrentScreen), drawingTime);

drawChild(canvas, getChildAt(mNextScreen), drawingTime);

} else {

final int count = getChildCount();

for (int i = 0; i < count; i++) {

drawChild(canvas, getChildAt(i), drawingTime);

}

}

}

canvas.restore();

}

@Override

protected void onLayout(boolean changed, int l, int t, int r, int b) {

int childLeft = 0;

final int count = getChildCount();

// 从左到右放置

for (int i = 0; i < count; i++) {

final View child = getChildAt(i);

if (child.getVisibility() != View.GONE) {

// Log.i(TAG, "child" + i + "-" + child.getMeasuredWidth());

final int childWidth = child.getMeasuredWidth();

child.layout(childLeft, 0, childLeft + childWidth, child

.getMeasuredHeight());

childLeft += childWidth;

}

}

}

private void snapToDestination(int currentScreen) {

final int screenWidth = getWidth();

final int whichScreen = (mScrollX + (screenWidth / 2)) / screenWidth;

snapToScreen(whichScreen);

}

private void snapToScreen(int whichScreen) {

if (!mScroller.isFinished()) {

return;

}

clearChildrenCache();

enableChildrenCache();

whichScreen = Math.max(0, Math.min(whichScreen, getChildCount() - 1));

boolean changeScreens = whichScreen != mCurrentScreen;

mNextScreen = whichScreen;

View focusedChild = getFocusedChild();

if (focusedChild != null && changeScreens

&& focusedChild == getChildAt(mCurrentScreen)) {

focusedChild.clearFocus();

}

final int newX = whichScreen * getWidth();

final int delta = newX - mScrollX;

mScroller.startScroll(mScrollX, 0, delta, Math.abs(delta) * 2);

// Log.i(TAG, "delta=" + delta);

invalidate();

}

@Override

protected void onDraw(Canvas canvas) {

final int count = getChildCount();

for (int i = 0; i < count; i++) {

final View child = getChildAt(i);

drawChild(canvas, child, getDrawingTime());

}

}

@Override

public boolean dispatchUnhandledMove(View focused, int direction) {

if (direction == View.FOCUS_LEFT) {

if (getCurrentScreen() > 0) {

snapToScreen(getCurrentScreen() - 1);

}

} else if (direction == View.FOCUS_RIGHT) {

if (getCurrentScreen() < getChildCount() - 1) {

snapToScreen(getCurrentScreen() + 1);

}

}

return super.dispatchUnhandledMove(focused, direction);

}

@Override

public boolean onInterceptTouchEvent(MotionEvent ev) {

// if (isLocked) {

// return true;

// }

final int action = ev.getAction();

final float x = ev.getX();

// final float y = ev.getY();

switch (action) {

case MotionEvent.ACTION_MOVE:

final int xDiff = (int) Math.abs(x - mLastMotionX);

// final int yDiff = (int) Math.abs(y - mLastMotionY);

final int touchSlop = mTouchSlop;

boolean xMoved = xDiff > touchSlop;

if (xMoved) {

if (xMoved) {

mTouchState = TOUCH_STATE_SCROLLING;

enableChildrenCache();

}

}

break;

case MotionEvent.ACTION_DOWN:

mLastMotionX = x;

mTouchState = mScroller.isFinished() ? TOUCH_STATE_REST

: TOUCH_STATE_SCROLLING;

break;

case MotionEvent.ACTION_CANCEL:

case MotionEvent.ACTION_UP:

clearChildrenCache();

mTouchState = TOUCH_STATE_REST;

}

return mTouchState != TOUCH_STATE_REST;

}

@Override

public boolean onTouchEvent(MotionEvent ev) {

if (mVelocityTracker == null) {

mVelocityTracker = VelocityTracker.obtain();

}

mVelocityTracker.addMovement(ev);

final int action = ev.getAction();

final float x = ev.getX();

switch (action) {

case MotionEvent.ACTION_DOWN:

if (!mScroller.isFinished()) {

mScroller.abortAnimation();

}

mLastMotionX = x;

break;

case MotionEvent.ACTION_MOVE:

if (mTouchState == TOUCH_STATE_SCROLLING) {

final int delteX = (int) (mLastMotionX - x);

mLastMotionX = x;

if (delteX < 0) {

if (mScrollX > 0) {

scrollBy(Math.max(-mScrollX, delteX), 0);

}

} else if (delteX > 0) {

final int availableToScroll = getChildAt(

getChildCount() - 1).getRight()

- mScrollX - getWidth();

if (availableToScroll > 0) {

scrollBy(Math.min(availableToScroll, delteX), 0);

}

}

}

break;

case MotionEvent.ACTION_UP:

if (mTouchState == TOUCH_STATE_SCROLLING) {

final VelocityTracker velocityTracker = mVelocityTracker;

velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);

int velocityX = (int) velocityTracker.getXVelocity();

if (velocityX > SNAP_VELOCITY && mCurrentScreen > 0) {

snapToScreen(mCurrentScreen - 1);

} else if (velocityX < -SNAP_VELOCITY

&& mCurrentScreen < getChildCount() - 1) {

snapToScreen(mCurrentScreen + 1);

} else {

snapToDestination(mCurrentScreen);

}

if (mVelocityTracker != null) {

mVelocityTracker.recycle();

mVelocityTracker = null;

}

}

mTouchState = TOUCH_STATE_REST;

break;

case MotionEvent.ACTION_CANCEL:

mTouchState = TOUCH_STATE_REST;

break;

}

System.out.println("total count=" + this.getChildCount());

return true;

}

}

3. [代码][Java]代码

import java.util.List;

import android.content.Context;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;

import android.widget.BaseAdapter;

import android.widget.ImageView;

import android.widget.TextView;

import com.huawei.constant.Constant;

import com.huawei.constant.EnumLogClass;

import com.huawei.ui.maintab.bean.GridDataModle;

import com.huawei.util.AndroidUtil;

import com.huawei.util.LogUtil;

public class MyAdapter extends BaseAdapter {

private static final String TAG="MyAdapter";

private List<GridDataModle> list = null;

private Context myContext = null;

public MyAdapter(Context context, List<GridDataModle> arraylist) {

super();

list = arraylist;

this.myContext = context;

}

@Override

public int getCount() {

if (list != null && list.size() > 0) {

return list.size();

} else {

return 0;

}

}

@Override

public Object getItem(int arg0) {

if (list != null && list.size() > 0) {

return list.get(arg0);

} else {

return null;

}

}

@Override

public long getItemId(int position) {

return position;

}

@Override

public View getView(int position, View view, ViewGroup parant) {

GridDataModle bean = list.get(position);

LayoutInflater mInflater = LayoutInflater.from(myContext);

if (view == null && bean!=null) {

view = mInflater.inflate(Constant.LAYOUT_GRID_ITEM_VIEW, null);

ImageView iv = (ImageView) view.findViewById(Constant.ID_LIST_ITEM);

TextView tv = (TextView) view.findViewById(Constant.ID_LIST_ITEM_TAG);

LogUtil.log(EnumLogClass.i, TAG, bean.icon+"--item icon");

iv.setBackgroundResource(AndroidUtil.GetIDbyName(bean.icon, "drawable", myContext));

tv.setText(AndroidUtil.GetIDbyName(bean.name, "string", myContext));

view.setTag(bean);

} else {

if( bean!=null){

bean = (GridDataModle) view.getTag();

}

}

return view;

}

}

4. [代码][Java]代码

public class GridDataModle {

public String id;

public String name;

public String icon;

public String className;

public GridDataModle(String id, String name, String icon, String className) {

super();

this.id = id;

this.name = name;

this.icon = icon;

this.className = className;

}

}

5. [代码][Java]代码

import java.util.ArrayList;

public class GroupModle {

public String id;

public String icon;

public ArrayList<GridDataModle> childs;

public GroupModle(String id, String icon) {

super();

this.id = id;

this.icon = icon;

childs=new ArrayList<GridDataModle>();

}

public void addChild(GridDataModle child) {

childs.add(child);

}

public void remove(GridDataModle child) {

if (child == null) {

return;

}

if (childs.contains(child)) {

childs.remove(child);

}

}

}

6. [代码][Java]代码

public class InfoBean {

public int id;

public String str;

public int imageId;

/**

* @param id

* @param str

* @param imageId

*/

public InfoBean(int id, String str, int imageId) {

super();

this.id = id;

this.str = str;

this.imageId = imageId;

}

}

7. [文件] item1.xml ~ 994B下载(25)

<?xml version="1.0" encoding="utf-8"?>

<View showMessage="0">

<Group id='group1' icon='bg_main_1'>

<Item id='1' name='@string/agency_register' icon='u399_original' className='ui.agency.AgencyRegistActivity'></Item>

<Item id='2' name='@string/agency_deposit' icon='u201_original' className='ui.agency.DepositActivity'></Item>

<Item id='3' name='@string/agency_remittance' icon='u576_original' className='ui.agency.RemittanceActivity'></Item>

<Item id='4' name='@string/agency_emoney' icon='u205_original' className='ui.agency.EmoneyActivity'></Item>

<Item id='5' name='@string/agency_sell_airtime' icon='u211_original' className='ui.agency.AgencySellAirtimeActivity'></Item>

</Group>

<Group id='group2' icon='bg'>

<Item id='4' name='@string/agency_emoney' icon='u205_original' className='ui.agency.EmoneyActivity'></Item>

<Item id='5' name='@string/agency_sell_airtime' icon='u211_original' className='ui.agency.AgencySellAirtimeActivity'></Item>

</Group>

</View>

8. [文件] AndroidUtil.java ~ 1KB下载(26)

import android.content.Context;

import com.huawei.constant.Constant;

import com.huawei.constant.EnumLogClass;

public class AndroidUtil {//帮助类

private static final String TAG="AndroidUtil";

public static final int EXIT_APPLICATION = 0x0001;//退出代号

private Context mContext;

public AndroidUtil(Context context) {

this.mContext = context;

}

// // 完全退出应用

// public void exit() {

//

//// 1.5 - 2.1之前下面两行是ok的,2.2之后就不行了,所以不通用

//// ActivityManager am =

//// (ActivityManager)mContext.getSystemService(Context.ACTIVITY_SERVICE);

//// am.restartPackage("com.tutor.exit");

//

//Intent mIntent = new Intent();

//mIntent.setClass(mContext, AgencyMainActivity.class);

//// 这里设置flag还是比较 重要的

//mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);//清除stack中所有前面的activity

//// 发出退出程序指示

//mIntent.putExtra("flag", EXIT_APPLICATION);

//mContext.startActivity(mIntent);

// }

public static int GetIDbyName(String imgname, String type,Context context) {

LogUtil.log(EnumLogClass.i, TAG, imgname+"--"+type);

int revalue = context.getResources().getIdentifier(imgname, type,

Constant.Package_name.substring(0, Constant.Package_name.length()-1));

if (revalue == 0) {

revalue = Constant.Default_identifer;

}

return revalue;

}

}

9. [文件] ParseFromXmlToModle.java ~ 3KB下载(24)

import java.io.InputStream;

import java.util.ArrayList;

import java.util.List;

import org.w3c.dom.Element;

import org.w3c.dom.NamedNodeMap;

import org.w3c.dom.Node;

import org.w3c.dom.NodeList;

import com.huawei.constant.EnumLogClass;

import com.huawei.ui.maintab.bean.GridDataModle;

import com.huawei.ui.maintab.bean.GroupModle;

import com.huawei.util.AndroidUtil;

import com.huawei.util.DomUtil;

import com.huawei.util.LogUtil;

public class ParseFromXmlToModle {

private static final String TAG="ParseFromXmlToModle";

public static boolean showable=false;

public static boolean IsShowMessage(Node node){

if (node.getNodeType() == Element.ELEMENT_NODE) {

NamedNodeMap attrs = node.getAttributes();

String showMessage = attrs.item(0).getNodeValue();

if(showMessage!=null && "1".equals(showMessage)){

return true;

}

return false;

}

return false;

}

public static List<GroupModle> getData(String path) {

List<GroupModle> groups = new ArrayList<GroupModle>();

InputStream domis = DomUtil.loadStreamFromLocalFile(path);

Element el = DomUtil.getRootElement(domis);

showable=IsShowMessage(el);

if (el.getNodeType() == Element.ELEMENT_NODE) {

NodeList nodelist = el.getChildNodes();

if (nodelist != null && nodelist.getLength() > 0) {

for (int i = 0; i < nodelist.getLength(); i++) {

Node node = nodelist.item(i);

if (node.getNodeType() == Element.ELEMENT_NODE) {

GroupModle modle = createGroupModle(node);

groups.add(modle);

}

}

}

}

return groups;

}

private static GridDataModle createGridDataModle(Node el) {

GridDataModle modle = null;

if (el.getNodeType() == Element.ELEMENT_NODE) {

NamedNodeMap attrs = el.getAttributes();

String id = attrs.item(0).getNodeValue();

String name = attrs.item(1).getNodeValue();

String icon = attrs.item(2).getNodeValue();

String className = attrs.item(3).getNodeValue();

LogUtil.log(EnumLogClass.i, TAG, "id=" + id + " name=" + name + " icon=" + icon

+ " className=" + className);

modle = new GridDataModle(id, name, icon, className);

return modle;

}

return null;

}

private static GroupModle createGroupModle(Node el) {

GroupModle groupModle = null;

if (el.getNodeType() == Element.ELEMENT_NODE) {

NamedNodeMap attrs = el.getAttributes();

String id = attrs.item(0).getNodeValue();

String icon = attrs.item(1).getNodeValue();

groupModle = new GroupModle(id, icon);

GridDataModle modle = null;

NodeList nodelist = el.getChildNodes();

if (nodelist != null && nodelist.getLength() > 0) {

for (int i = 0; i < nodelist.getLength(); i++) {

Node node = nodelist.item(i);

if (node.getNodeType() == Element.ELEMENT_NODE) {

modle = createGridDataModle(node);

groupModle.addChild(modle);

}

}

}

return groupModle;

}

return null;

}

}

10. [文件] DomUtil.java ~ 4KB下载(27)

import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;

import javax.xml.parsers.DocumentBuilderFactory;

import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;

import org.w3c.dom.Element;

import org.w3c.dom.NamedNodeMap;

import org.w3c.dom.Node;

import org.w3c.dom.NodeList;

import com.huawei.constant.Constant;

public class DomUtil {

/**

* @return 得到doc创建对象的工厂类

* @throws ParserConfigurationException

*/

public static DocumentBuilder getDocumentBuilder()

throws ParserConfigurationException {

DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory

.newInstance();

return docBuilderFactory.newDocumentBuilder();

}

/**

* @param fileName

*文件名

* @return 返回一个输入流对象

*/

public static InputStream loadStreamFromLocalFile(String fileName) {

InputStream in = null;

try {

in = Class.forName(Constant.AndroidUitl_class_path)

.getResourceAsStream("/assets/" + fileName);

} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

if (in == null) {

throw new RuntimeException("load file is err!");

}

return in;

}

/**

* @param parent

*父元素

* @param attrName

*属性名称

* @param attrValue

*属性值

* @return 返回对应的元素

*/

public static Element getElementByAttr(Element parent, String attrName,

String attrValue) {

NodeList childs = parent.getChildNodes();

for (int i = 0; i < childs.getLength(); i++) {

Node child = childs.item(i);

if (child.getNodeType() == Element.ELEMENT_NODE) {

NamedNodeMap attrs = child.getAttributes();

for (int j = 0; j < attrs.getLength(); j++) {

Node attr = attrs.item(j);

String tempAttrName = attr.getNodeName();

String tempAttrValue = attr.getNodeValue();

if (tempAttrName.equalsIgnoreCase(attrName)

&& tempAttrValue != null

&& tempAttrValue.equalsIgnoreCase(attrValue)) {

return (Element) child;

}

}

}

}

return null;

}

/**

* @param inputStream

*输入流对象

* @return 根元素

*/

public static Element getRootElement(InputStream inputStream) {

// get the root element from the inputStream;

if (inputStream == null) {

throw new RuntimeException("getRootElement:the inputStream is null");

}

Element root = null;

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

try {

DocumentBuilder builder = factory.newDocumentBuilder();

Document dom = builder.parse(inputStream);

root = dom.getDocumentElement();

} catch (Exception e) {

e.printStackTrace();

}

return root;

}

public static void transDomToString(Node e, StringBuffer sb) {

switch (e.getNodeType()) {

case Node.ELEMENT_NODE:

String eNSP = e.getNamespaceURI();

String eName = e.getNodeName();

String NSPandName = eNSP == null ? eName : eNSP + eName;

sb.append("<");

sb.append(NSPandName);

NamedNodeMap attrs = e.getAttributes();

for (int j = 0; j < attrs.getLength(); j++) {

Node attr = attrs.item(j);

String attrName = attr.getNodeName();

String attrValue = attr.getNodeValue();

sb.append(" ");

sb.append(attrName);

sb.append("=");

sb.append("\"");

sb.append(attrValue);

sb.append("\"");

sb.append(" ");

}

sb.append('>');

NodeList childs = e.getChildNodes();

for (int i = 0; i < childs.getLength(); i++) {

transDomToString(childs.item(i), sb);

}

sb.append("<");

sb.append('/');

sb.append(eName);

sb.append('>');

break;

case Node.TEXT_NODE:

sb.append(e.getNodeValue());

break;

}

}

}

赞助本站

人工智能实验室

相关热词: 屏幕 切换

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港