I have an activity that rotates png image by the SeekBar progress. And it draws me multiple needles. why it does that?
The needle and the speedometer are not perfect, they are just for testings :)
In onCreate:
#Override
public void onCreate(Bundle savedInstanceState) {
...
iv = (ImageView)findViewById(R.id.imageView1);
bMap = BitmapFactory.decodeResource(getResources(), R.drawable.rodykle);
workingBitmap = Bitmap.createBitmap(bMap);
mutableBitmap = workingBitmap.copy(Bitmap.Config.ARGB_8888, true);
yourCanvas = new Canvas(mutableBitmap);
later i use this void
public void drawneedle(){
yourCanvas.rotate(speed, mutableBitmap.getWidth()/2, mutableBitmap.getHeight()/2);
yourCanvas.save(Canvas.MATRIX_SAVE_FLAG);
yourCanvas.drawBitmap(mutableBitmap, 0,0, null);
yourCanvas.restore();
iv.setImageBitmap(mutableBitmap);
}
Layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mtr="http://schemas.android.com/apk/res/com.mindtherobot.samples.thermometer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top"
android:orientation="vertical" >
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:max="270" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/spidometras" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40sp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" />
</RelativeLayout>
</LinearLayout>
Do you clear the inner circle of the previously drawn content?
You can do that with canvas.drawColor(0, Mode.CLEAR);
Also, in my opinion, you need to add the configChanges flag to your activity's tag in the AndroidManifest.xml file, to prevent onCreate to run more than once when activity rotates.
android:configChanges="orientation|screenLayout|screenSize|smallestScreenSize"
To know that the activity rotated, you need to override the
onConfigurationChanged(Config newConfig)
method and check the new orientation of the newConfig variable
Related
I am trying to start a shining affect animation on an Image view.
the problem is that the animation does not show on screen.
It is work only when I start it inside a button listener.
this is my shine_effect.xml file:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:centerColor="#beffffff"
android:endColor="#00ffffff"
android:startColor="#00ffffff" />
</shape>
this is my layout xml file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradient"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/relativeLayout"
android:layout_width="170dp"
android:layout_height="170dp"
android:layout_centerInParent="true">
<ImageView
android:id="#+id/img"
android:layout_width="170dp"
android:layout_height="170dp"
android:contentDescription="#string/desc"
android:src="#drawable/logo" />
<ImageView
android:id="#+id/shine"
android:layout_width="50dp"
android:layout_height="170dp"
android:layout_marginStart="-50dp"
android:contentDescription="#string/desc"
android:src="#drawable/shine_effect" />
</RelativeLayout>
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/relativeLayout"
android:layout_centerHorizontal="true"
android:layout_marginTop="43dp"
android:text="#string/pending"
android:textColor="#android:color/white" />
</RelativeLayout>
and my activity onCreate method:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chat_pending);
img=(ImageView)findViewById(R.id.img) ;
shine=(ImageView)findViewById(R.id.shine) ;
shine_anim=new TranslateAnimation(0, img.getWidth()+ shine.getWidth(),0,
0);
shine_anim.setDuration(550);
shine_anim.setFillAfter(true);
shine_anim.setRepeatMode(Animation.RESTART);
shine_anim.setInterpolator(new AccelerateDecelerateInterpolator());
shine_anim.setRepeatMode(Animation.INFINITE);
shine.startAnimation(shine_anim);
}
It is because the ImageView has not layouted yet so the width is 0. You can give it a layout cycle and start the animation then.
img.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
img.getViewTreeObserver().removeOnGlobalLayoutListener(this);
// Create and start animation
}
});
Alternatively if your image width is always static, you can convert e.g. that 170dp to px and use that value when creating the TranslateAnimation instead of using getWidth() methods of views.
Call your animation in onWindowFocusChanged method
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if(hasFocus) {
shine_anim = new TranslateAnimation(0, img.getWidth() + shine.getWidth(), 0,
0);
shine_anim.setDuration(550);
shine_anim.setFillAfter(true);
shine_anim.setRepeatMode(Animation.RESTART);
shine_anim.setInterpolator(new AccelerateDecelerateInterpolator());
shine_anim.setRepeatMode(Animation.INFINITE);
shine.startAnimation(shine_anim);
}
}
I’m trying to creating a layout that contains a "SurfaceView" at the top with a horizontal toolbar that is section into 3 segments in the bottom, however my SurfaceView which contains camera preview is only the only element that is showing. Please point out the error in my layout xml or provide me the similar layout xml, Thanks.
Below is my layout & updates based on user recommendations
Attempt # 1 (RelativeLayout as root):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LayoutForPreview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:screenOrientation="portrait" >
<SurfaceView
android:id="#+id/surfaceViewBarcodeScanner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/linearLayoutToolbar"
android:layout_gravity="top"
android:scaleType="fitXY" />
<LinearLayout
android:id="#+id/linearLayoutToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="#drawable/scanner_bottom_left" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.68"
android:scaleType="fitXY"
android:src="#drawable/scanner_bottom_center_toolbar" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="#drawable/scanner_bottom_right_landscape_button" />
</LinearLayout>
</RelativeLayout>
Below is my desired GUI look:
Attempt #1 Result , device snapshot , which only shows the SurfaceView:
Snapshot of eclipse GUI tool, which shows what the layout should look like.
Attempt # 2 (LinearLayout as root):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LayoutForPreview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:screenOrientation="portrait" >
<SurfaceView
android:id="#+id/surfaceViewBarcodeScanner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:scaleType="fitXY"
android:layout_weight="1" />
<LinearLayout
android:id="#+id/linearLayoutToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="bottom" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="#drawable/scanner_bottom_left" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.68"
android:scaleType="fitXY"
android:src="#drawable/scanner_bottom_center_toolbar" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="#drawable/scanner_bottom_right_landscape_button" />
</LinearLayout>
</LinearLayout>
Attempt #2 , Result , Device snapshot :
Issues:
1) Toolbar appears on top rather than on bottom
2) Camera preview freezes & app crashes. For some reason LinearLayout causes the Camera error 1001 , and I think its related to preview sizes.
Attempt #3 (Add toolbar programmatically to either Relative or Linear layout in activity onCreate).
LinearLayout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LayoutForPreview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:screenOrientation="portrait" >
<SurfaceView
android:id="#+id/surfaceViewBarcodeScanner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:scaleType="fitXY"
android:layout_weight="1" />
</LinearLayout>
Toolbar defined in separate XML added later via Java code:
<?xml version="1.0" encoding="UTF-8"?>
<!-- LinearLayout that contains toolbar that is divided into 3 sections horizontally , layout_below="#+id/BarcodeScannerFrame-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayoutToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="#drawable/scanner_bottom_left" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.68"
android:scaleType="fitXY"
android:src="#drawable/scanner_bottom_center_toolbar" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="#drawable/scanner_bottom_right_landscape_button" />
</LinearLayout>
onCreate,onResume,other relevant code snippets of my activity only, the LinearLayout toolbar is added to Linear or Relative layout at runtime:
//import not included
public class ScanVinFromBarcodeActivity extends Activity {
// camera object that is used globally in this activity and also passed
// reference to PreviewSurface inner class
private Camera globalCamera;
private int cameraId = 0;
// bitmap that would created after picture is taken and converted from
// camera bytes
private Bitmap bmpOfTheImageFromCamera = null;
// global flag whether a camera has been detected
private boolean isThereACamera = false;
// layout for this activity
private LinearLayout RelativeLayoutBarcodeScanner= null;
// CameraPreview extends SurfaceView displays preview of images from the
// Camera
private CameraPreview newCameraPreview = null;
// used to inflate the xml layout
private SurfaceView surfaceViewBarcodeScanner = null;
private boolean cameraPreviewing = false;
// this continueToAutomaticallyDecode flag is initially set to TRUE, but
// will be set to FALSE on the first successful decode OR when a crucial
// method in the code process fails or throws an exception
private volatile boolean continueToAutomaticallyDecode = true;
// global flag used to indicate picture taking & decoding is in progress
private volatile boolean takingPictureAndDecodeInprogress = false;
// Bitmap options for bitmap creation from camera picture
BitmapFactory.Options options = null;
// used for samsung galaxy s devices only
private Matrix rotationMatrix90CounterClockWise = null;
// Reader is class from zxing used to decode barcodes
Reader reader = null;
// DecodeHintType hashtable is used to provide help to the zxing Reader
// class
Hashtable<DecodeHintType, Object> decodeHints = null;
//
private boolean onTouchEvent = true;
//
private OrientationEventListener orientationEventListener = null;
// 1 means the screen is PORTRAIT and 2 means screen is LANDSCAPE
private int latestScreenOrientation = 1;
//
Camera.Parameters Flash = null;
//
private String globalVIN = null;
//
private Handler handler = null;
//
private LinearLayout barcodeVinScannerToolbar = null;
public boolean isContinueToAutomaticallyDecode() {
return continueToAutomaticallyDecode;
}
public void setContinueToAutomaticallyDecode(
boolean continueToAutomaticallyDecode) {
this.continueToAutomaticallyDecode = continueToAutomaticallyDecode;
}
public boolean isTakingPictureAndDecodeInprogress() {
return takingPictureAndDecodeInprogress;
}
public void setTakingPictureAndDecodeInprogress(
boolean takingPictureAndDecodeInprogress) {
this.takingPictureAndDecodeInprogress = takingPictureAndDecodeInprogress;
}
/*
* This method , finds FEATURE_CAMERA, opens the camera, set parameters ,
* add CameraPreview to layout, set camera surface holder, start preview
*/
#SuppressLint("InlinedApi")
private void initializeGlobalCamera() {
try {
if (!getPackageManager().hasSystemFeature(
PackageManager.FEATURE_CAMERA)) {
Toast.makeText(this, "No camera on this device",
Toast.LENGTH_LONG).show();
} else { // check for front camera ,and get the ID
cameraId = findFrontFacingCamera();
if (cameraId < 0) {
Toast.makeText(this, "No front facing camera found.",
Toast.LENGTH_LONG).show();
} else {
Log.d("ClassScanViewBarcodeActivity",
"camera was found , ID: " + cameraId);
// camera was found , set global camera flag to true
isThereACamera = true;
// OPEN
globalCamera = getGlobalCamera(cameraId);
// parameters auto focus
globalCamera.getParameters().setFocusMode(
Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
// set picture format to JPEG, everytime makesure JPEg
globalCamera.getParameters().setPictureFormat(
ImageFormat.JPEG);
autoFocusSetupForBarcode(globalCamera);
/*
* START early setup variables & setting used in
* jpegCallback in order to optimize the jpegCallback code
*/
options = new BitmapFactory.Options();
// option set for down sampling he captured image taken from
// the camera in order to MemoryOutOfBounds exception
options.inSampleSize = 4;
// image quality rather than speed in order to achieve early
// barcode detection & decode
options.inPreferQualityOverSpeed = false;
// Samsung galaxy S only , rotate to correct orientation
// ,and capture only the image within the guidance rectangle
rotationMatrix90CounterClockWise = new Matrix();
rotationMatrix90CounterClockWise.postRotate(90);
// early variable used by zxing to decode method
decodeHints = new Hashtable<DecodeHintType, Object>();
decodeHints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
decodeHints.put(DecodeHintType.PURE_BARCODE, Boolean.TRUE);
decodeHints.put(DecodeHintType.ASSUME_CODE_39_CHECK_DIGIT,
Boolean.TRUE);
reader = new MultiFormatReader();
turnOnFlashlight(globalCamera);
// pass surfaceView to CameraPreview
newCameraPreview = new CameraPreview(this, globalCamera) {
#Override
public boolean onTouchEvent(MotionEvent event) {
Log.d("ClassScanViewBarcodeActivity",
" onTouchEvent(MotionEvent event) ");
onTouchEvent = true;
globalCamera
.autoFocus(autoFocusCallbackForAutomaticScan);
return super.onTouchEvent(event);
}
};
// pass CameraPreview to Layout
RelativeLayoutBarcodeScanner.addView(newCameraPreview);
// give reference SurfaceView to camera object
globalCamera.setPreviewDisplay(surfaceViewBarcodeScanner
.getHolder());
// PREVIEW
if (cameraPreviewing != true) {
globalCamera.startPreview();
}
Log.d("ClassScanViewBarcodeActivity",
"camera opened & previewing");
}
}// end else ,check for front camera
}// end try
catch (Exception exc) {
// in case of exception release resources & cleanup
if (globalCamera != null) {
globalCamera.stopPreview();
cameraPreviewing = false;
globalCamera.setPreviewCallback(null);
globalCamera.release();
globalCamera = null;
options = null;
rotationMatrix90CounterClockWise = null;
reader = null;
}
Log.d("ClassScanViewBarcodeActivity initializeGlobalCamera() exception:",
exc.getMessage());
exc.printStackTrace();
}// end catch
}// end ini
/* this method detect whether the camera flashlight a.k.a torch feature is available to be turned on then turns on the light*/
public void turnOnFlashlight(Camera camera) {
Log.d("ClassScanViewBarcodeActivity",
"turnOnFlashlight(Camera camera )");
boolean flag = false;
Context context = null;
if (camera != null) {
Log.d("ClassScanViewBarcodeActivity",
"turnOnFlashlight() , FEATURE_CAMERA_FLASH: " + flag);
context = RelativeLayoutBarcodeScanner.getContext();
if (context != null) {
flag = context.getPackageManager().hasSystemFeature(
PackageManager.FEATURE_CAMERA_FLASH);
if (flag) {
Flash = camera.getParameters();
Flash.setFlashMode("torch");
camera.setParameters(Flash);
}// end if camera feature is available
else {
Log.d("ClassScanViewBarcodeActivity",
"turnOnFlashlight() , FEATURE_CAMERA_FLASH: "
+ flag);
}
}// end if context not null
}// end camera not null
}// end turnOnFlashlight(Camera camera )
// onCreate, instantiates layouts & surfaceView used for video preview
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_barcode_vin_scanner);
Log.d("ClassScanViewBarcodeActivity", "onCreate ");
// create surfaceView for previewing of camera image
RelativeLayoutBarcodeScanner = (LinearLayout) findViewById(R.id.LayoutForPreview);
surfaceViewBarcodeScanner = (SurfaceView) findViewById(R.id.surfaceViewBarcodeScanner);
barcodeVinScannerToolbar = (LinearLayout) findViewById(R.id.linearLayoutToolbar);
initializeGlobalCamera();
//*****TOOLBAR IS ADDED*****
if (RelativeLayoutBarcodeScanner!=null && barcodeVinScannerToolbar!=null)
{
//surfaceViewBarcodeScanner.addChildrenForAccessibility(list);
RelativeLayoutBarcodeScanner.addView(barcodeVinScannerToolbar);
}
// instantiate orientationEventListener
orientationEventListener = new OrientationEventListener(this,
SensorManager.SENSOR_DELAY_NORMAL) {
#Override
public void onOrientationChanged(int arg0) {
/*
latestScreenOrientation = ScreenUtility
.getScreenOrientation(RelativeLayoutBarcodeScanner.getContext());
Log.d("ClassScanViewBarcodeActivity",
"latestScreenOrientation: " + latestScreenOrientation);
if (orientationEventListener.canDetectOrientation()) {
orientationEventListener.enable();
Log.d("ClassScanViewBarcodeActivity",
"enabled orientationEventListener: "
+ String.valueOf(orientationEventListener
.canDetectOrientation()));
} else {
Log.d("ClassScanViewBarcodeActivity",
"enabled orientationEventListener: "
+ String.valueOf(orientationEventListener
.canDetectOrientation()));
}
*/
}
};
handler = new Handler();
}// end onCreate
#Override
protected void onResume() {
Log.d("ClassScanViewBarcodeActivity, onResume() globalCamera:",
String.valueOf(globalCamera));
initializeGlobalCamera();
//*****TOOLBAR IS ADDED*****
if (RelativeLayoutBarcodeScanner!=null && barcodeVinScannerToolbar!=null)
{
//surfaceViewBarcodeScanner.addChildrenForAccessibility(list);
RelativeLayoutBarcodeScanner.addView(barcodeVinScannerToolbar);
}
if (orientationEventListener != null) {
orientationEventListener.enable();
}
super.onResume();
}
#Override
protected void onStop() {
if (globalCamera != null) {
globalCamera.stopPreview();
cameraPreviewing = false;
globalCamera.setPreviewCallback(null);
globalCamera.release();
globalCamera = null;
}
if (orientationEventListener != null) {
orientationEventListener.disable();
}
super.onStop();
}
#Override
protected void onPause() {
if (globalCamera != null) {
globalCamera.stopPreview();
cameraPreviewing = false;
globalCamera.setPreviewCallback(null);
globalCamera.release();
globalCamera = null;
options = null;
rotationMatrix90CounterClockWise = null;
reader = null;
}
if (orientationEventListener != null) {
orientationEventListener.disable();
}
super.onPause();
}// end onPause()
//other irrelevant code was not included
}//end activity
Attempt #3, result, screen freezes , no particular error or exception reported:
Error log:
**If the eclipse GUI tool shows the desired look , than why is the toolbar still missing??? I would like to have the toolbar in the bottom , preferably using RelativeLayout without any crashes or screen freezes. Any help will be appreciated.
I'm using Samsung Galaxy S3 for testing.
Thanks.**
You wanted something like this?
the layout I used is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:id="#+id/linearLayoutToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
<ImageView
android:id="#+id/imageView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:src="#drawable/ic_launcher"
/>
<ImageView
android:id="#+id/imageView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:src="#drawable/ic_launcher"
/>
<ImageView
android:id="#+id/imageView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:src="#drawable/ic_launcher"
/>
</LinearLayout>
<SurfaceView
android:id="#+id/surfaceViewBarcodeScanner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/linearLayoutToolbar"
/>
</RelativeLayout>
Please note that, since I didn't have your images in my res/drawable folder, I replaced them with ic_launcher.
Also note that I used an ldpi device running Froyo (API level 2.2). This is why the image is smaller than yours and the UI differs slighthly (...). Anyway, it works at every resolution and with every os version.
Add this to your LinearLayout containing imageView
android:layout_alignParentBottom="true"
What you really want is not to use a Relativelayout but instead use a Linearlayout as your root. Then set the surfaceview weight to 1, something like:
<SurfaceView
android:id="#+id/surfaceViewBarcodeScanner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"/>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/scanner_bottom_left" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/scanner_bottom_center_toolbar" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/scanner_bottom_right_landscape_button" />
</LinearLayout>
You forgot to tell the surfaceView to be above the linearLayout. Your code will need to look similar to this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/linearLayoutToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/scanner_bottom_left" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/scanner_bottom_center_toolbar" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/scanner_bottom_right_landscape_button" />
</LinearLayout>
<SurfaceView
android:id="#+id/surfaceViewBarcodeScanner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/linearLayoutToolbar" />
</RelativeLayout>
Why do you use RelativeLayout as a root layout, I think it is much simplier to use LinearLayou with layout_weight parameter in one of children view:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<SurfaceView
android:layout_weight="1"
android:id="#+id/surfaceViewBarcodeScanner"
android:layout_width="match_parent"
android:layout_height="0dp" />
<!-- LinearLayout that contains toolbar that is divided into 3 sections horizontally -->
<LinearLayout
android:id="#+id/linearLayoutToolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/scanner_bottom_left" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/scanner_bottom_center_toolbar" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/scanner_bottom_right_landscape_button" />
</LinearLayout>
</LinearLayout>
try changing the layout to this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LayoutForPreview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:screenOrientation="portrait" >
<SurfaceView
android:id="#+id/surfaceViewBarcodeScanner"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="top"
android:scaleType="fitXY"
android:layout_weight="1" />
<LinearLayout
android:id="#+id/linearLayoutToolbar"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".1"
android:orientation="horizontal"
android:layout_gravity="bottom" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="#drawable/scanner_bottom_left" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.68"
android:scaleType="fitXY"
android:src="#drawable/scanner_bottom_center_toolbar" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="#drawable/scanner_bottom_right_landscape_button" />
</LinearLayout>
I see a few mistakes in your initial XML
1. In the surfaceview you use:
android:layout_above="#+id/linearLayoutToolbar"
You should use #+id when you create an Id but when you want to make a reference you should only do #id like this:
android:layout_above="#id/linearLayoutToolbar"
2. You can't do a reference to another object that isn't created yet! So you should put the surfaceview below de linearlayout like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LayoutForPreview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:screenOrientation="portrait" >
<LinearLayout
android:id="#+id/linearLayoutToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="#drawable/scanner_bottom_left" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.68"
android:scaleType="fitXY"
android:src="#drawable/scanner_bottom_center_toolbar" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="#drawable/scanner_bottom_right_landscape_button" />
</LinearLayout>
<SurfaceView
android:id="#+id/surfaceViewBarcodeScanner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/linearLayoutToolbar"
android:layout_gravity="top"
android:scaleType="fitXY" />
</RelativeLayout>
3. You should add weight to your 3 ImageViews like this:
android:layout_weight="1"
Some small changes in your initial layout will lead to remove the error. You need to use android:layout_height="0dp" , defining 0dp will help your surfaceview to fit in your screen.
<SurfaceView
android:id="#+id/surfaceViewBarcodeScanner"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_above="#+id/linearLayoutToolbar"
/>
And I've not found use of below attribute in SurfaceView.
android:layout_gravity="top"
android:scaleType="fitXY"
Checkout this layout designs, how android:layout_height="0dp" works, and how android:layout_width="0dp" works.
I have used that kind of layouts in many apps, and here is how should be your layout. No tricks, no praying for luck, this is just the clean, happy, and always-working way to achieve it
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:screenOrientation="portrait" >
<SurfaceView
android:id="#+id/surfaceViewBarcodeScanner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/linearLayoutToolbar"
android:layout_alignParentTop="true" />
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayoutToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="#drawable/scanner_bottom_left" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.68"
android:scaleType="fitXY"
android:src="#drawable/scanner_bottom_center_toolbar" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="#drawable/scanner_bottom_right_landscape_button" />
</LinearLayout>
</RelativeLayout>
here you have a preview on one of my apps.
The posted code is adapted to yours so a copy/paste will do it. please note that its everything in a simple file, so you have to change slightly your activity
i got a problem with setContentView which throws me a null pointer.
In my mainFrame i got a small SurfaceView which takes about 50% of the screen.
I wanted to implement a method which makes that SurfaceView go Full Screen if you long clicked it. I did it like this:
final FrameLayout frame = (FrameLayout) findViewById(R.id.frame_layout);
frame.setOnLongClickListener(new OnLongClickListener() {
boolean clicked = false;
#Override
public boolean onLongClick(View v) {
if (clicked){
clicked = false;
(MyActivity.this).setContentView(R.layout.main);
} else {
clicked = true;
(MyActivity.this).setContentView(R.layout.fullScreen);
}
return true;
}
});
Can someone help me how to fix this problem?
Greetings
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="right"
android:orientation="vertical"
android:weightSum="1"
android:background="#drawable/background_new" >
<TextView
android:text="#string/measures"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/text_measures"
android:textColor="#ff444444"
android:layout_marginTop="30dp"
android:layout_marginLeft="10dp"
/>
<ImageButton
android:contentDescription="#string/desc_edge"
android:layout_toRightOf="#id/text_measures"
android:id="#+id/edges_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/edges_black"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="30dp"
android:onClick="edge_handler"
android:background="#null"
/>
<FrameLayout
android:background="#xml/border"
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginBottom="35dp"
android:layout_marginRight="200dp"
android:layout_marginTop="80dp"
android:layout_below="#id/text_measures"
>
</RelativeLayout>
I know it looks like a FrameLayout but dont get fooled it was done by someone else and it is actually a SurfaceView.
Just change the layout parameters of the SurfaceView onLong click of frame. No need to setContentView again.
LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
surfaceView.setLayoutParams(lp);
I have two main issues which are closely linked. I am looking at these problems from a programmatic point of view.
(1) - I wish to take a screenshot of the contents of a SPECIFIC layout, i.e. a ScrollView nested in a LinearLayout.
(2) - As the ScrollView has content that spills out of the screen (hence scrolling made possible), how can I ensure that the screenshot includes the elements that are not visible on the screen?
This is the current block of code I use. It does the job of taking a screenshot but only for the entire screen. This is even though R.id.boss is the ID of the ScrollView and not the main LinearLayout.
View view = findViewById(R.id.boss);
View v = view.getRootView();// this does not seem to make a difference
v.setDrawingCacheEnabled(true);
v.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
v.buildDrawingCache(true);
Bitmap b = Bitmap.createBitmap(u.getDrawingCache());
v.setDrawingCacheEnabled(false);
Thanks in advance.
EDIT:
I've made a few mistakes. I used R.id.boss which is the wrong resource. I am now able to take a screenshot of the scrollview alone, less the out-of-screen parts.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/boss"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="F"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Analyze via image URL"
android:textAppearance="?android:attr/textAppearanceSmall" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<EditText
android:id="#+id/mUrl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:text="http://" >
<requestFocus />
</EditText>
<ImageView
android:id="#+id/call"
android:layout_width="75dp"
android:layout_height="50dp"
android:layout_weight="0.3"
android:text="ABC"
android:src="#drawable/run" />
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="ABC"
android:textAppearance="?android:attr/textAppearanceSmall" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/filepath"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.55" />
<ImageView
android:id="#+id/cam"
android:layout_width="75dp"
android:layout_height="50dp"
android:layout_weight="0.15"
android:src="#drawable/cam" />
<ImageView
android:id="#+id/browse"
android:layout_width="75dp"
android:layout_height="50dp"
android:layout_weight="0.15"
android:src="#drawable/folder"
android:text="B" />
<ImageView
android:id="#+id/upload"
android:layout_width="75dp"
android:layout_height="50dp"
android:layout_weight="0.15"
android:src="#drawable/run"
android:text="A" />
</LinearLayout>
<LinearLayout
android:id="#+id/baba"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scroll"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_weight="0.7" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="186dp"
android:orientation="vertical" >
<ImageView
android:id="#+id/pic"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Facial recognition"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/avmarwe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Gender and age"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/skahasd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Expression and mood"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/dsfsfs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Celebrity Facial Match"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/text4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" >
<Button
android:id="#+id/c"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_weight="0.7"
android:text="" />
<Button
android:id="#+id/share"
android:layout_width="70dp"
android:layout_height="50dp"
android:layout_weight="0.3"
android:text="" />
</LinearLayout>
</LinearLayout>
Thanks to you guys, I've finally found out what was wrong.
View v = view.getRootView(); should not be used because it will call the root view which I do not want. I mistakenly thought this did not make a difference because I had entered the wrong resource ID.
MeasureSpec somehow did not give a good account of the width and height. So I ended up using another method:
...
ScrollView z = (ScrollView) findViewById(R.id.scroll);
int totalHeight = z.getChildAt(0).getHeight();
int totalWidth = z.getChildAt(0).getWidth();
u.layout(0, 0, totalWidth, totalHeight);
...
As ScrollView's total height can be determined by the single child element that it has.
After making these changes, I am now able to take a screenshot of a nested ScrollView and all its contents, visible or not. For anyone interested, here is the block of code including the saving of the bitmap:
View u = findViewById(R.id.scroll);
u.setDrawingCacheEnabled(true);
ScrollView z = (ScrollView) findViewById(R.id.scroll);
int totalHeight = z.getChildAt(0).getHeight();
int totalWidth = z.getChildAt(0).getWidth();
u.layout(0, 0, totalWidth, totalHeight);
u.buildDrawingCache(true);
Bitmap b = Bitmap.createBitmap(u.getDrawingCache());
u.setDrawingCacheEnabled(false);
//Save bitmap
String extr = Environment.getExternalStorageDirectory().toString() + File.separator + "Folder";
String fileName = new SimpleDateFormat("yyyyMMddhhmm'_report.jpg'").format(new Date());
File myPath = new File(extr, fileName);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(myPath);
b.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
MediaStore.Images.Media.insertImage(getContentResolver(), b, "Screen", "screen");
}catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try this it works fine for me
TableLayout tabLayout = (TableLayout) findViewById(R.id.allview);
if (tabLayout != null) {
Bitmap image = Bitmap.createBitmap(tabLayout.getWidth(),
tabLayout.getHeight(), Config.ARGB_8888);
Canvas b = new Canvas(image);
tabLayout.draw(b);
}
EDIT : after seeing OP's comment
You dont need to think about new activities at all.. Say you are in Activity right now.. Layout A is the main layout for the activity, Layout B and C are two child layouts inside Layout A. Like this,
Layout A -> Parent
|
-------Layout B
|
-------Layout C
Now if you want to take screenshot of C only
1) in onCreate() of activity
LinearLayout myCLayout = (LinearLayout)this.findViewbyId(R.id.my_c_layout);
ViewTreeObserver vto = myCLayout.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
//fully drawn, no need of listener anymore
myCLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
getDrawingBitmap();
}
});
where getDrawingBitmap() is a function..to take your screenshot..
public void getDrawingBitmap(){
LinearLayout myCLayout = (LinearLayout)this.findViewbyId(R.id.my_c_layout);
Bitmap b = myCLayout.getDrawingCache();
File file = saveBitmapAsFile(b);
}
EDIT: For ScrollView
I never tried it.. But I think you can do this..
1) first override scrollView, and override onMeasure function..
public class MyScrollView extends ScrollView{
public MyScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
#Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
super.onMeasure(widthMeasureSpec, yourFullScrollViewHeight));
}
}
and use MyScrollView in your layout.. here yourFullScrollViewHeight is the height of all scrollView content you need to take screenshot of.. I never tried this.. But it might work..
Here is the exact solution you want, It will display entire screen including content hidden in your ScrollView
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
FrameLayout root = (FrameLayout) inflater.inflate(R.layout.activity_main, null); // activity_main is UI(xml) file we used in our Activity class. FrameLayout is root view of my UI(xml) file.
root.setDrawingCacheEnabled(true);
Bitmap bitmap = getBitmapFromView(this.getWindow().findViewById(R.id.frameLayout)); // here give id of our root layout (here its my FrameLayout's id)
Display bitmap in your ImageView or use it as you want. Enjoy..
I also had this problem and coded it myself.
I used this code to take screenshot of whole layout.
I did modified the list size and some mathematical items.
See the following website,
Try this code
public Bitmap screenShot(View view)
{
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(),
view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
return bitmap;
}
I have this xml :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#drawable/photo0"
android:id="#+id/imagBackground">
<TextView android:layout_width="20dip" android:layout_height="20dip"
android:layout_marginLeft="250dip" android:layout_marginTop="15dip" android:background="#FFFFFF"
android:id="#+id/index" android:text="0" android:textColor="#000000">
</TextView>
<ImageView android:layout_marginTop="280dip"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:background="#drawable/anim_ctrl_panel" android:id="#+id/change">
</ImageView>
</LinearLayout>
and over this I must draw some rectangular by code. How to do this ?
I tried this :
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
layout = (LinearLayout) findViewById(R.id.imagBackground);
changeImage = (ImageView) findViewById(R.id.change);
index = (TextView) findViewById(R.id.index);
draw();
}
private void draw() {
System.out.println("desenam");
int width = 50;
int height = 100;
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
Paint paint = new Paint();
paint.setColor(Color.BLUE);
Canvas canvas = new Canvas(bitmap);
canvas.drawColor(Color.RED);
canvas.drawRect(25, 50, 75, 150, paint);
ImageView imageView = new ImageView(this);
imageView.setImageBitmap(bitmap);
layout.addView(imageView);
setContentView(layout);
}
but the rectangulars are on the bottom on screen. How to set the location where to put them?
My guess is, the reason why it's in the bottom of the page is because of the LinearLayout: in the end you will have 3 children: TextView, ImageView and ImageView, all below each other.
A few possible solutions:
Add a FrameLayout inside the LinearLayout and add the ImageViews inside it, so the hierarchy would be:
LinearLayout
TextView
FrameLayout
ImageView
ImageView
Use a RelativeLayout instead of the LinearLayout and align all the edges of the second ImageView with the first one
Create a custom ImageView class, for example "com.foo.bar.MyImageView", which of course extends ImageView. Override onDraw:
public void onDraw(Canvas canvas) {
super.onDraw(canvas); // This will render the original image
// ... and here you can have the code to render the rectangle
}
In the xml you replace
<ImageView ...
with
<com.foo.bar.MyImageView ...
I would go for the last solution, since from a performance point of view it's the best.
try this code:
Point left=new Point(x, y);
paint.setColor(Color.parseColor("#00CCFF"));
paint.setStyle(Style.FILL);
canvas.drawCircle(left.x, left.y, 9, paint);
So you have to create a Point using pixels and then draw a rectangle around it otherwise it doesn't know where to draw
Why dont you do this in the layout file itself:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#drawable/photo0"
android:id="#+id/imagBackground">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#android:color/darker_gray">
<LinearLayout android:layout_width="fill_parent"
android:layout_margin="5dip"
android:layout_height="fill_parent" android:background="#android:color/black">
<TextView android:layout_width="20dip" android:layout_height="20dip"
android:layout_marginLeft="250dip" android:layout_marginTop="15dip" android:background="#FFFFFF"
android:id="#+id/index" android:text="0" android:textColor="#000000">
</TextView>
<ImageView android:layout_marginTop="280dip"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:background="#drawable/anim_ctrl_panel" android:id="#+id/change">
</ImageView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Try to change your LinearLayout to this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:gravity="top" android:layout_gravity="top"
android:layout_height="fill_parent" android:background="#drawable/photo0"
android:id="#+id/imagBackground">
...