2

さて、私はこれを理解しようとしていましたが、下に進む方法がわからないのは、背景が@ drawable/patterrepeatに設定されているScrollViewです。

<ScrollView 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"
    android:fillViewport="false" 
    android:background="@drawable/patternrepeat">
</ScrollView>

これで、patternrepeatは次のようなxmlドローアブルになります

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android" 
    android:src="@drawable/pattern"
    android:tileMode="repeat"/>

これで、このビットマップのsrcはPNG画像になります。

課題は、この「プログラム的に」ScrollView ----> Bitmap -----> Bitmap OriginalPNGSourcesにアクセスする方法です。

この理由は、元のソースがタイル化されてビットマップを作成し、それがScrollViewにロードされて背景を作成するためです...

これをどのように進めますか?

4

1 に答える 1

1
// get bg drawable first
Drawable d = scrollView.getBackground();

// there are many types of drawables. In you case BitmapDrawable 
// (according to your xml) should be returned. So...
if (d instanceof BitmapDrawable) { // check drawable type just in case
    Bitmap sourceBitmap = ((BitmapDrawable)d).getBitmap();
}

sourceBitmapはあなたが必要とするものです。

于 2012-12-29T07:40:56.263 に答える