如何同时在屏幕上同时绘制2张PNG图片
问题描述:
我想知道如何在屏幕上绘制两张PNG图片。如何同时在屏幕上同时绘制2张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>
什么是Java代码来实例化XML布局,并在同一时间在屏幕上显示两个ImageViews? 只需拨打setContentView(R.drawable.paperxml);
即可在启动时崩溃我的应用程序。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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 android:id="@+id/paperid"
android:src="@drawable/paperrepresentation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView android:id="@+id/rockid"
android:src="@drawable/rockrepresentation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
说明:
答
与更换XML
-
RelativeLayout
不使用android:orientation="vertical"
。 - 每个视图应该有
android:layout_width
和android:layout_height
。 - 仅在第一个元素中添加
xmlns:android
。
答
调用setContentView(R.drawable.paperxml);
不会崩溃您的代码 - 它是您的XML文件。 Macarse对你的问题有正确的答案,并保持你的代码相同!
您可能还想看看View Tutorials以了解设置XML和使用不同View对象的一些示例。
答
我把XML放进去,但它只显示一个ImageView下面是我拍摄的模拟器的屏幕截图。 i852.photobucket.com/albums/ab87/thomasjakway1/Capture.png其值得一提的是,所示的文件是paperrepresentation
如果你看够硬,你会看到在底部有第二个非常微小的图像。你只需要增加规模。
我把XML,但它只显示一个ImageView 下面是我采取的模拟器的屏幕截图。 http://i852.photobucket.com/albums/ab87/thomasjakway1/Capture.png 值得一提的是,显示的文件是paperrepresentation – dragonwrenn 2010-07-13 00:53:44
这是因为大小。尝试使用'layout_width'和'layout_height'使用类似“40dp”的东西。 还要记住LinearLayout被设置为Vertical。 – Macarse 2010-07-13 00:59:01