我正在做一些非常基本的事情,比如在屏幕上添加一个按钮。该代码在 Andorid 2.3 中运行良好,但在 Android 4.1.1 中无法运行。
RelativeLayout mainLayout = new RelativeLayout(this);
mainLayout.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
ImageView titleView = new ImageView(this);
Bitmap _bitmap = returnScaledBitmap(R.drawable.headertext, display.getWidth()*50/100,display.getHeight()*15/100);
titleView.setImageBitmap(_bitmap);
titleView.setId(R.drawable.headertext);
RelativeLayout.LayoutParams textLayout = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
textLayout.addRule(RelativeLayout.ALIGN_PARENT_TOP);
titleView.setPadding(display.getWidth()*35/100, display.getWidth()*1/100,display.getWidth()*1/100,display.getWidth()*1/100);
titleView.setLayoutParams(textLayout);
mainLayout.addView(titleView);
setContentView(mainLayout);
此代码在 2.3.3 的 HTC EVO 4G 上运行良好。但不是在运行 4.1.1 的三星 Galaxy S3 上。这是我的清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.myorg"
android:versionCode="6"
android:versionName="1.0"
android:icon="@drawable/icon"
android:installLocation="preferExternal"
>
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="@drawable/icon"
android:label="@string/app_name" android:logo="@drawable/icon" android:debuggable="false">
<activity
android:screenOrientation="landscape"
android:label="@string/app_name"
android:name=".splash" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".homepage"
android:screenOrientation="landscape">
</activity>
</application>
<uses-permission android:name="android.permission.VIBRATE"></uses-permission>
</manifest>
请告诉我我做错了什么。