Czy ktoś może mi wyjaśnić deklarowany znacznik XML w tym przykładzie i teorię za jego użyciem?

Czytam Beginning Android 4 Development, aw rozdziale 5 mówi o tymGaleria iImageVievs i wprowadzadeklarować-stylowe Znacznik XML bez wyjaśnienia jego celu .. Próbowałem znaleźć jakieś informacje również na temat referencji, bez szczęścia .. Na przykład mamy następujące:

res / values ​​/ attrs.xml

<?xml version=”1.0” encoding=”utf-8”?> 
<resources>
    <declare-styleable name=”Gallery1”>
        <attr name=”android:galleryItemBackground” />
    </declare-styleable>
</resources>

przykład.java

public class GalleryActivity extends Activity {
[...]
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState);    
        setContentView(R.layout.main);
        Gallery gallery = (Gallery) findViewById(R.id.gallery1);
        gallery.setAdapter(new ImageAdapter(this)); 
        [...]
    }

    [...]

    public class ImageAdapter extends BaseAdapter {
        [...]
        int itemBackground;

        public ImageAdapter(Context c) {
            context = c;
            //---setting the style---
            TypedArray a = obtainStyledAttributes(
            R.styleable.Gallery1); 
            itemBackground = a.getResourceId(
                        R.styleable.Gallery1_android_galleryItemBackground, 0);
            a.recycle();
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            ImageView imageView;
            [...]
            imageView.setBackgroundResource(itemBackground);
            return imageView; 
        }
    }
}

Przeczytałem kod kilka razy i naprawdę nie rozumiem celu zdefiniowania tego styluGaleria1 z singlemattr dziecko tylko zimię atrybut .. możesz mi pomóc? Czy to jestgalleryItemBackground coś dostarczonego przez system, czy jest to coś przez nas zdefiniowanego? Co robimy w tym fragmencie kodu?

Z góry dziękuję za wszelką pomoc!

questionAnswers(1)

yourAnswerToTheQuestion