英文:
How can I merge pictures Android?
问题
我有2张图片,一张是背景,另一张是完整的图片。
我想要将它们合成一张图片,就像一张在另一张上面,然后将它们保存在您的手机上作为一张图片。
我应该学习和研究哪个JAVA库?
如果您能指导我使用在Android Studio开发的同一库,我将不胜感激。
英文:
I have 2 pictures, one is a background and the other is a complete picture.
I want to create one image from both of them as if one is above the other and save them on your cell phone as one image
Which JAVA library should I study and research?
I would be happy if you would refer me to the same library I develop in Android Studio.
答案1
得分: 0
是的,你可以这样做:
文件夹 drawable -> 新建 -> drawable 资源文件 -> 选择文件名并点击确定
然后你会得到以下内容:
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
</selector>
在 selector
标签内部,放置 layer-list
标签(记得闭合标签),在 layer-list
标签内部,放置 item
标签。
例如,你的结果可以是这样的:
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item>
</item>
<item>
</item>
</layer-list>
</item>
</selector>
现在你可以自定义这两个项目。如果你想要在项目中放置图像,你可以像这样编写代码:
<item
android:gravity="center_vertical|center_horizontal"
android:drawable="@drawable/YOUR_IMAGE"
android:width="96dp"
android:height="96dp"
tools:ignore="UnusedAttribute" />
如果你想要放置一个对象的形状,比如一个矩形,你可以像这样编写代码:
<item>
<shape
android:shape="rectangle">
<solid
android:color="#000000" />
<size
android:width="1080px"
android:height="1920px" />
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp" />
</shape>
</item>
现在你的图像由两个图像(或其他内容)组成,如果你想要使用它,你只需要在你的 layout_activity.xml
文件中调用 android:background="@drawable/YOUR_FILE_NAME"
。
有了这些信息,我认为你可以解决你的问题,再见
英文:
Yes you can, this is what you have to do:
Folder drawable -> new -> drawable resource file -> choose the name of the file and click ok
and this is what you get
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
</selector>
Inside the tags selector
put the tag <layer-list>
(remember to close the tag) and inside the layer-list
put the tag <item>
your result can be this for example:
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item>
</item>
<item>
</item>
</layer-list>
</item>
</selector>
Now you can customize your 2 items, if you want to put an image inside your item you can write your code like this:
<item
android:gravity="center_vertical|center_horizontal"
android:drawable="@drawable/YOUR_IMAGE"
android:width="96dp"
android:height="96dp"
tools:ignore="UnusedAttribute" />
if you want to put a shape of an object like a rectangle you can write your code like this:
<item>
<shape
android:shape="rectangle">
<solid
android:color="#000000" />
<size
android:width="1080px"
android:height="1920px" />
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp" />
</shape>
</item>
Now you have your image composed with 2 images (or other things) and if you want to use it you can just call android:background="@drawable/YOUR_FILE_NAME"
inside your layout_activity.xml
for example
with this informations I think you can solve your problem, cya
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论