我想知道如何在屏幕上繪製兩張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,但它只顯示一個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