关闭

根据帧图自动生成android 动画xml文件--python脚本

标签: python脚本动画androidxml
310人阅读 评论(0) 收藏 举报
分类:

利用python脚本自动生成 android xml动画文件

import sys
import os
#imageName = sys.argv[1]
#num = sys.argv[2]
#order = sys.argv[1]
#duration = sys.argv[2]
#outfile = sys.argv[3]

order = raw_input("请输入顺序(True正序 False 逆序,默认False):\n")
if order.replace(' ', '')=="":
    order = False

oneshot = raw_input("是否循环(true循环 false不循环,默认true):\n")
if oneshot.replace(' ', '')=="":
    oneshot = "true"

duration = raw_input("请输入duration(默认100):\n")
if duration.replace(' ', '')=="":
    duration = 100
outfile = raw_input("请输入文件夹:\n")
outfile = outfile.replace(' ', '')
while outfile=="":
    outfile = raw_input("请输入文件夹:\n")
    outfile = outfile.replace(' ', '')



num = 10
imageName = ""
order = False
for rt, dirs, files in os.walk(outfile):
    num = len(files)
    f = files[num/2]
    imageName = os.path.splitext(f)[0]
    pos = imageName.rfind("_")
    imageName = imageName[:pos] 


#num = int(num)
duration = int(duration)
order = order == str(True)

xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<animation-list xmlns:android=\"http://schemas.android.com/apk/res/android\" android:oneshot=\"%s\">"%oneshot
n = num
while n >= 0:
    if order:
        i = num-n
    else:
        i = n

    if i<10:
        xml = xml + "\n<item android:drawable=\"@mipmap/%s_000%d\" android:duration=\"%d\" />" % (imageName,i,duration)
    else:
        xml = xml + "\n<item android:drawable=\"@mipmap/%s_00%d\" android:duration=\"%d\" />" % (imageName,i,duration)
    n = n - 1
xml = xml + "\n</animation-list>"    

print xml
with open('%s/out_xml'%outfile, 'w') as f:
    f.write(xml)

命令行中运行python脚本

$ /Users/mangues/Desktop/python_android_script/git2xml.py 
请输入顺序(True正序 False 逆序,默认False):
False
是否循环(true循环 false不循环,默认true):
true
请输入duration(默认100):
100
请输入文件夹:
/Users/mangues/Desktop/ww 
1
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:41377次
    • 积分:739
    • 等级:
    • 排名:千里之外
    • 原创:28篇
    • 转载:1篇
    • 译文:0篇
    • 评论:167条
    我的链接
    最新评论