如何同时在屏幕上绘制2个PNG图像
我想知道如何在屏幕上绘制两张PNG图片。
我的 XML 布局:(名为 paperxml.xml)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layoutid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/paperid"
android:src="@drawable/paperrepresentation"
/>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rockid"
android:src="@drawable/rockrepresentation"
android:layout_alignTop="@id/paperid"
/>
</RelativeLayout>
实例化 XML 布局并同时在屏幕上显示两个 ImageView 的 java 代码是什么? 只需调用 setContentView(R.drawable.paperxml);
就会导致我的应用程序在启动时崩溃。
I'd like to know how to draw two PNG pictures onto the screen.
My XML layout: (named paperxml.xml)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layoutid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/paperid"
android:src="@drawable/paperrepresentation"
/>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rockid"
android:src="@drawable/rockrepresentation"
android:layout_alignTop="@id/paperid"
/>
</RelativeLayout>
What would be the java code to instantiate the XML layout and display both ImageViews on the screen at the same time?
Simply calling setContentView(R.drawable.paperxml);
crashes my application on startup.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将 xml 替换为:
说明:
RelativeLayout
不使用android:orientation="vertical"
。android:layout_width
和android:layout_height
。xmlns:android
内容。Replace the xml with:
Explanation:
RelativeLayout
doesn't useandroid:orientation="vertical"
.android:layout_width
andandroid:layout_height
.xmlns:android
thing just in the first element.调用
setContentView(R.drawable.paperxml);
不会使您的代码崩溃 - 它会导致您的 XML 文件崩溃。 Macarse 对您的问题有正确的答案,并保持您的代码相同!您可能还想查看查看教程,了解一些示例设置 XML 并使用不同的视图对象。
Calling
setContentView(R.drawable.paperxml);
is not crashing your code - it's your XML file. Macarse has the correct answer to your problem, and keep your code the same!You may also want to look at the View Tutorials for some examples of setting up your XML and using different View objects.
如果您仔细观察,您会发现底部有第二个非常小的图像。您只需要增加规模即可。
If you look hard enough you will see that at the bottom there is a second very tiny image. You just need to increase the scale.