2016-08-12 51 views
0

那么我的应用程序应该让我拍一张我的脸的照片并显示它,直到我删除它,然后我可以再拍一张。我第一次打开应用程序时发生的事情是,布局背景的粉红色边线显示,但是当我拍照时,粉红线消失。这不应该发生,因为以上的宽度和高度match_parent即我设置底色位图中的ImageView的ImageView不适合屏幕两侧

的第二个问题是,当我设置背景的ImageView回背景这之前是在中心透明的,以便即使我将其设置回来,也可以看到相机指向的位置不会发生。屏幕应该恢复到透明中心,但它保持运行takePicture时所拍摄的屏幕截图。感谢您的帮助,因为我撕扯我的头发现在

enter image description here

background_view = (ImageView) view.findViewById(R.id.backround_view); 
      background = BitmapFactory.decodeResource(getResources(), R.drawable.camera_backround); 
      background_view.setImageBitmap(background); 

private void takePicture() { 
     if (picturePresent == false) { 
      edit_button.setVisibility(View.INVISIBLE); 

      pictureBitmap = getBitmapFromView(); 

      edit_button.setVisibility(View.VISIBLE); 

      closeCamera(); 
      stopBackgroundThread(); 

      BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), pictureBitmap); 
      background_view.setBackground(bitmapDrawable); 
      picturePresent = true; 

     } else { 
     } 
    } 


    private void deletePicture() { 
     if (picturePresent == true) { 
      startBackgroundThread(); 
      openCamera(mTextureView.getWidth(), mTextureView.getHeight()); 
      background_view.setImageBitmap(background); 
      picturePresent = false; 
     } else { 
     } 
    } 

    public Bitmap getBitmapFromView() { 
     Bitmap bitmap = mTextureView.getBitmap(); 
     Bitmap bitmap2 = BitmapFactory. decodeResource(getResources(), R.drawable.camera_backround); 
     Bitmap bmOverlay = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig()); 
     Canvas canvas = new Canvas(bmOverlay); 
     canvas.drawBitmap(bitmap, new Matrix(), null); 
     canvas.drawBitmap(bitmap2, new Matrix(), null); 
     return bmOverlay; 
    } 

XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:tools="http://schemas.android.com/tools" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      tools:context="yourfacelivewallpaper.alexcz.yourfacelivewallpaper.CameraFragment" 
       android:background="#ffbf1ec5"> 

    <!-- TODO: Update blank fragment layout --> 

    <view 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     class="yourfacelivewallpaper.alexcz.yourfacelivewallpaper.AutoFitTextureView" 
     android:id="@+id/texture" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true"/> 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/backround_view" 
     android:layout_centerVertical="true" 
     android:layout_centerHorizontal="true" 
     android:longClickable="false" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentStart="true"/> 

回答

1

android:scaleType =“fitXY”

将以上代码添加到xml文件中。

0

如果你的形象是小个你的ImageView它不会填满屏幕。您应该将android:scaleType="fitCenter"添加到您的ImageView的布局属性中。