Layout not found on Android 2.1
If I create own folder layout-w320dp with Eclipse Android 4.4
layout was correctly loaded.
If I trying this application on tablet with Android 2.1 application crashed.
layout was correctly loaded.
If I trying this application on tablet with Android 2.1 application crashed.
396LW NO topic_id
AD
Další témata ....(Topics)
public class ApokusActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new SampleView(this));
}
private static class SampleView extends View {
// CONSTRUCTOR
public SampleView(Context context) {
super(context);
setFocusable(true);
}
@Override
protected void onDraw(Canvas canvas) {
Paint paint = new Paint();
canvas.drawColor(Color.YELLOW);
paint.setFilterBitmap(true);
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),R.drawable.flower_blue);
int targetWidth = bitmapOrg.getWidth() * 2;
int targetHeight = bitmapOrg.getHeight() * 2;
Bitmap bmp = Bitmap.createBitmap(targetWidth, targetHeight,Bitmap.Config.ARGB_8888);
RectF rectf = new RectF(0, 0, targetWidth, targetHeight);
Canvas c = new Canvas(bmp);
Path path = new Path();
path.addRect(rectf, Path.Direction.CW);
c.clipPath(path);
c.drawBitmap( bitmapOrg, new Rect(0, 0, bitmapOrg.getWidth(), bitmapOrg.getHeight()),
new Rect(0, 0, targetWidth, targetHeight), paint);
Matrix matrix = new Matrix();
matrix.postScale(1f, 1f);
Bitmap resizedBitmap = Bitmap.createBitmap(bmp, 0, 0, targetWidth, targetHeight, matrix, true);
int h = bitmapOrg.getHeight();
canvas.drawBitmap(bitmapOrg, 10,10, paint);
canvas.drawBitmap(resizedBitmap, 10,10 + h + 10, paint);
}
}
}
WakeLock, PowerManager,uses-permission Android sample.
Main.java
AndroidManifest.xml
Main.java
public class Main extends Activity {
private SensorManager mSensorManager;
private PowerManager mPowerManager;
private WindowManager mWindowManager;
private WakeLock mWakeLock;
private Button button;
private TextView textView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try{
// Get an instance of the SensorManager
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
// Get an instance of the PowerManager
mPowerManager = (PowerManager) getSystemService(POWER_SERVICE);
// Get an instance of the WindowManager
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
mWindowManager.getDefaultDisplay();
// Create a bright wake lock
mWakeLock = mPowerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, getClass()
.getName());
setContentView(R.layout.main);
textView = (TextView)findViewById(R.id.textView1);
button = (Button)findViewById(R.id.button1);
button.setOnClickListener(mButtonStopListener);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e("onCreate", e.getMessage());
}
} // END onCreate
View.OnClickListener mButtonStopListener = new OnClickListener() {
public void onClick(View v) {
try {
mWakeLock.release();
textView.setText("mWakeLock.release()");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e("onPause",e.getMessage());
}
}
};
@Override
protected void onResume() {
super.onResume();
/*
* when the activity is resumed, we acquire a wake-lock so that the
* screen stays on, since the user will likely not be fiddling with the
* screen or buttons.
*/
try {
mWakeLock.acquire();
textView.setText("mWakeLock.acquire()");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e("onResume", e.getMessage());
}
}
@Override
protected void onPause() {
super.onPause();
// and release our wake-lock
try {
mWakeLock.release();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e("onPause",e.getMessage());
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="//schemas.android.com/apk/res/android"
package="cz.okhelp.Main"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.HARDWARE_TEST"></uses-permission>
<uses-permission android:name="android.permission.VIBRATE"></uses-permission>
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".ScreenBrightnessActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Try this trick.
In AndroidManifest - activity tag write this code
App hold data of a views if will to rotation of device.
In AndroidManifest - activity tag write this code
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
App hold data of a views if will to rotation of device.
<activity
android:name=".Tests_Activity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
int[] mArrayOfInt;
String[] mArrayOfString;
List<String> mList;
public void saveState(Bundle map)
{
map.putIntArray("mArrayOfInt", mArrayOfInt);
map.putStringArray("mArrayOfString", mArrayOfString);
map.putStringArrayList("mList", mList);
}
public void restoreState(Bundle map)
{
mArrayOfInt= map.getIntArray("mArrayOfInt");
mArrayOfString = map.getStringArray("mArrayOfString");
mList = map.getStringArrayList("mList");
}
Close one project:¨
-right click on project
- select Close project
Close more projects:
- right click on project
- select Close Unrelated Projects
Hide closed projects:
- package explorer
- view menu
- select Closed projects
-right click on project
- select Close project
Close more projects:
- right click on project
- select Close Unrelated Projects
Hide closed projects:
- package explorer
- view menu
- select Closed projects
Editace: 2013-12-16 13:55:27
Počet článků v kategorii: 396
Url:layout-not-found-on-android-2-1