当前位置:   article > 正文

Python 适配android左右布局图片_drawable-ldrtl

drawable-ldrtl
  1. res/
  2. drawable/
  3. a.png
  4. drawable-ldrtl/
  5. a.png // 对标 drawable/a.png 的 RTL 图标
  6. drawable-xhdpi/
  7. b.png
  8. drawable-ldrtl-xhdpi/
  9. b.png // 对标 drawable-xhdpi/b.png 的 RTL 图标

有了这个知识以后。

我们就知道 只需要将项目里面的 带left_xx_.png 的图 复制旋转。并且替换到新的目录 那么就完成了

主要针对左右箭头。。很显眼

  1. import os
  2. from PIL import Image
  3. def main():
  4. # 遍历所有的目录找出带左右文件的png
  5. for root, dirs, files in os.walk("/Users/liuan/AndroidStudioProjects/haive/haive-android"):
  6. for file in files:
  7. if (file.endswith(".png") and file.__contains__("right")) or (
  8. file.__contains__("left") and file.endswith(".png")):
  9. # # 获取文件名
  10. name = file.split(".")[0]
  11. # # 获取文件的路径
  12. path = os.path.join(root, file)
  13. # 已有ldrtl 则无需再次进行拼接
  14. if path.__contains__("ldrtl"):
  15. continue
  16. # 临时文件目录无需进行替换
  17. if path.__contains__("/build/intermediates"):
  18. continue
  19. parentPath = path.split("/")[-2]
  20. # drawable-xxhdpi 中间插入 -ldrtl
  21. # "-"前面插入数据
  22. newList = []
  23. index = 0
  24. for x in parentPath.split("-"):
  25. if index == 1:
  26. newList.append("ldrtl")
  27. newList.append(x)
  28. index = index + 1
  29. # 将数组转换成字符串由"-"连接
  30. newParentPath = "-".join(newList)
  31. newFilePath = path.replace(parentPath, newParentPath)
  32. # 判断newFilePath 父目录是否存在 不存在则创建
  33. if not os.path.exists(os.path.dirname(newFilePath)):
  34. os.makedirs(os.path.dirname(newFilePath))
  35. if not os.path.exists(newFilePath):
  36. # 图片旋转180度并保存为新的路径
  37. print("以下文件将会被替换##########################")
  38. print(name)
  39. print(path)
  40. print(newFilePath)
  41. im = Image.open(path)
  42. im = im.rotate(180)
  43. im.save(newFilePath)
  44. if __name__ == '__main__':
  45. main()

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/474930
推荐阅读
相关标签
  

闽ICP备14008679号