Witam Próbowałem napisać funkcję, która wykonuje zrzut ekranu. Znalazłem kod, który doskonale to robi za pomocą przycisku listy kliknięć, ale po usunięciu listy kliknięć przycisku i po prostu spróbuj zrobić zrzut ekranu w czasie tworzenia mapy bitowej, którą otrzymuję jest pusty. Dlaczego to się dzieje?Android wykonuje zrzut ekranu
układ:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/LinearLayout01"
>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="munch"
android:id="@+id/munchscreen"
/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="500dp"
android:id="@+id/screenshots"
/>
aktywny:
public class MainActivity extends Activity {
LinearLayout L1;
ImageView image;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
L1 = (LinearLayout) findViewById(R.id.LinearLayout01);
Button but = (Button) findViewById(R.id.munchscreen);
but.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
View v1 = L1.getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap bm = v1.getDrawingCache();
BitmapDrawable bitmapDrawable = new BitmapDrawable(bm);
image = (ImageView) findViewById(R.id.screenshots);
image.setBackgroundDrawable(bitmapDrawable);
}
});
}
}
możesz spróbować wpisać kod w 'onPostCreate()' –