2017-04-04 6 views
1

입니다.이 작은 게임에는 많은 이미지 버튼을 사용합니다! 문제는 응용 프로그램이 일부 휴대폰에 뒤쳐져 있다는 것입니다.하지만 문제는 찾을 수 없습니다. 나는 그것이 원활하게 실행 얻었는지 이제 문제는우리는 ImageButton을 많이 사용하고 응용 지연은

enter image description here

: 여기

당신이 그것을 더 상상할 수있는 스크린 샷입니까? Pls는 나는 우리의 도움이 필요합니다 :) 다음은 메뉴 XML입니다 :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="de.unikatproduktion.smaragdhunter.MenueActivity" 
android:background="@drawable/menuehintergrund"> 

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageButton 
     android:layout_width="90dp" 
     android:layout_height="45dp" 
     android:id="@+id/btn_zurvollversion" 
     android:scaleType="fitXY" 
     android:background="@drawable/btnzurvollversion" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginTop="10dp" /> 

    <ImageView 
     android:background="@drawable/smaragdmenueanim" 
     android:id="@+id/imgshhg" 
     android:scaleType="fitXY" 
     android:layout_width="250dp" 
     android:layout_height="100dp" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginTop="110dp" /> 

    <ImageButton 
     android:layout_width="90dp" 
     android:layout_height="45dp" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" 
     android:id="@+id/btnmusikanaus" 
     android:scaleType="fitXY" 
     android:background="@drawable/buttonmusikanausnewclickeddddd" 
     android:layout_marginTop="10dp" 
     android:layout_marginLeft="275dp" 
     android:layout_marginRight="15dp" 
     android:layout_gravity="right" /> 

    <ImageView 
     android:id="@+id/zauberermenue" 
     android:scaleType="fitXY" 
     android:background="@drawable/zauberermenuehgg" 
     android:layout_height="60dp" 
     android:layout_above="@+id/btn_highscore" 
     android:layout_toRightOf="@+id/btn_appbewerten" 
     android:layout_toEndOf="@+id/btn_appbewerten" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginTop="221dp" 
     android:layout_width="60dp" /> 

    <ImageButton 
     android:id="@+id/btn_appbewerten" 
     android:scaleType="fitXY" 
     android:background="@drawable/btnappbewerten" 
     android:layout_width="90dp" 
     android:layout_height="45dp" 
     android:layout_marginTop="10dp" 
     android:layout_marginLeft="15dp" /> 

    <ImageButton 
     android:id="@+id/btn_start" 
     android:scaleType="fitXY" 
     android:background="@drawable/btnstart" 
     android:layout_height="90dp" 
     android:layout_alignParentBottom="true" 
     android:layout_alignLeft="@+id/btn_highscore" 
     android:layout_alignStart="@+id/btn_highscore" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:layout_marginTop="375dp" 
     android:layout_gravity="center_horizontal" 
     android:layout_width="220dp" /> 

    <Spinner 
     android:layout_width="220dp" 
     android:layout_height="90dp" 
     android:id="@+id/schwierigkeitsgrad" 
     android:background="@drawable/btnschwierigkeit" 
     android:layout_marginTop="280dp" 
     android:scrollbarSize="100dp" 
     android:foregroundGravity="center" 
     style="@style/Widget.AppCompat.Spinner" 
     android:animationCache="false" 
     android:animateLayoutChanges="false" 
     android:alwaysDrawnWithCache="false" 
     android:clipChildren="false" 
     android:elevation="0dp" 
     android:layout_gravity="center_horizontal" 
     android:dropDownSelector="@android:drawable/list_selector_background" 
     android:popupElevation="@dimen/activity_horizontal_margin" 
     android:spinnerMode="dropdown" /> 

    <TextView 
     android:text="Die Vollversion bietet ein besseres Spielerlebnis!" 
     android:singleLine="true" 
     android:scrollHorizontally="true" 
     android:ellipsize="marquee" 
     android:marqueeRepeatLimit="marquee_forever" 
     android:focusable="true" 
     android:focusableInTouchMode="true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:textColor="#000000" 
     android:textStyle="bold" 
     android:id="@+id/werbeview" 
     android:textSize="20sp" 
     android:layout_marginLeft="4dp" 
     android:layout_gravity="bottom|center" 
     android:layout_marginBottom="7dp" /> 

    <ImageButton 
     android:layout_width="90dp" 
     android:layout_height="45dp" 
     android:background="@drawable/btnenglisch" 
     android:id="@+id/sprache" 
     android:scaleType="fitXY" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginTop="60dp" /> 

    <ImageButton 
     android:id="@+id/insta" 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginLeft="60dp" 
     android:layout_marginTop="220dp" 
     android:background="#00000000" 
     android:scaleType="fitXY" 
     app:srcCompat="@drawable/instaiconklein" /> 
</FrameLayout> 

+0

검사에게 이미지의 크기를 확인할 수 있습니다, 그들이해야 너보다 더 크지 않아. –

답변

2

비트 맵을 다시 사용하면 게임을 시작할 때마다 디코딩 할 필요가 없습니다. 이 코드에서 같은 BitmapFactory.OptionsInBitmap를 사용할 수 있습니다

public class ImageCache { 

Set<SoftReference<Bitmap>> mReusableBitmaps; 

protected Bitmap getBitmapFromReusableSet(BitmapFactory.Options options) { 
    Bitmap bitmap = null; 

    if (mReusableBitmaps != null && !mReusableBitmaps.isEmpty()) { 
     synchronized (mReusableBitmaps) { 
      final Iterator<SoftReference<Bitmap>> iterator 
        = mReusableBitmaps.iterator(); 
      Bitmap item; 

      while (iterator.hasNext()) { 
       item = iterator.next().get(); 

       if (null != item && item.isMutable()) { 
        // Check to see it the item can be used for inBitmap. 
        if (canUseForInBitmap(item, options)) { 
         bitmap = item; 

         // Remove from reusable set so it can't be used again. 
         iterator.remove(); 
         break; 
        } 
       } else { 
        // Remove from the set if the reference has been cleared. 
        iterator.remove(); 
       } 
      } 
     } 
    } 
    return bitmap; 
} 

int getBytesPerPixel(Bitmap.Config config) { 
    if (config == Bitmap.Config.ARGB_8888) { 
     return 4; 
    } else if (config == Bitmap.Config.RGB_565) { 
     return 2; 
    } else if (config == Bitmap.Config.ARGB_4444) { 
     return 2; 
    } else if (config == Bitmap.Config.ALPHA_8) { 
     return 1; 
    } 
    return 1; 
} 
public boolean canUseForInBitmap(Bitmap candidate, BitmapFactory.Options targetOptions) { 

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 
     // From Android 4.4 (KitKat) onward we can re-use if the byte size of 
     // the new bitmap is smaller than the reusable bitmap candidate 
     // allocation byte count. 
     int width = targetOptions.outWidth/targetOptions.inSampleSize; 
     int height = targetOptions.outHeight/targetOptions.inSampleSize; 
     int byteCount = width * height * getBytesPerPixel(candidate.getConfig()); 
     return byteCount <= candidate.getAllocationByteCount(); 
    } 

    // On earlier versions, the dimensions must match exactly and the inSampleSize must be 1 
    return candidate.getWidth() == targetOptions.outWidth 
      && candidate.getHeight() == targetOptions.outHeight 
      && targetOptions.inSampleSize == 1; 
} 

public void addInBitmapOptions(BitmapFactory.Options options) { 
    // inBitmap only works with mutable bitmaps, so force the decoder to 
    // return mutable bitmaps. 
    options.inMutable = true; 

    if (this != null) { 
     // Try to find a bitmap to use for inBitmap. 
     Bitmap inBitmap = getBitmapFromReusableSet(options); 

     if (inBitmap != null) { 
      // If a suitable bitmap has been found, set it as the value of 
      // inBitmap. 
      options.inBitmap = inBitmap; 
     } 
    } 
} 
public Bitmap decodeSampledBitmapFromFile(Resources res,int id) { 

    final BitmapFactory.Options options = new BitmapFactory.Options(); 

    BitmapFactory.decodeResource(res, id , options); 

    // If we're running on Honeycomb or newer, try to use inBitmap. 
    addInBitmapOptions(options); 

    return BitmapFactory.decodeResource(res, id ,options); 
} 

을 나는이 : 당신을 위해 작동 희망, 그렇지 않은 경우 것은이 answer

+0

감사합니다. :) 새로운 클래스를 만들고이 코드를 붙여 넣기 만하면됩니까? – jordy

+0

예, 다음과 같습니다 :'bitmap = new ImageCache.decodeSampledBitmapFromFile (getResources, R.drawable.your_img); ' –

+0

괜찮아요. 초보자입니다. 시도해 보겠습니다. 할 수 없다면 어쩌면 저를 도울 수 있습니까? 나는 모든 것을 내 물건으로 보낼 수있다. – jordy

4

이미지가 높은 해상도를 가질 때 일반적으로 발생합니다. 장치가 오버 헤드를 렌더링하려고 할 때 앱이 충돌 할 수있는 앱 전체에 하나의 ImageView이있을 수 있습니다.

+0

다른 휴대 전화에서 이미지의 해상도를 조정하려면 어떻게해야합니까? – jordy

+0

[9-patch-resizer] (https://github.com/redwarp/9-patch-resizer) 도구를 사용하면 큰 해상도의 이미지를 찍어 다른 화면 밀도에 비해 더 낮은 해상도로 동일한 이미지를 생성 할 수 있습니다. 따라서 생성 된 이미지를 프로젝트의'res' 폴더에 넣으면 런타임에 적절한 이미지가 사용됩니다. –

0

설정/개발자 옵션에서 '프로필 GPU 렌더링'을 사용 설정하여 앱이 지연되는 것을 전혀 렌더링하지 않는지 확인할 수 있습니다.

관련 문제