Я читаю Начало разработки Android 4, и в главе 5 рассказывается о Galleryи ImageVievsи вводится XML-тег declare-styleableбез объяснения его назначения. Я попытался найти некоторая информация также по ссылке, но безуспешно.. Например, у нас есть следующее:
res/values/attrs.xml
<?xml version=”1.0” encoding=”utf-8”?>
<resources>
<declare-styleable name=”Gallery1”>
<attr name=”android:galleryItemBackground” />
</declare-styleable>
</resources>
example.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;
}
}
}
Я прочитал код несколько раз, и я не Я действительно не понимаю цель определения этой стильной Gallery1с одним дочерним элементом attrтолько с атрибутом name. Вы можете мне помочь? Эта галереяItemBackgroundпредоставлена системой или определена нами? Что мы делаем в этом фрагменте кода?
Заранее спасибо за любую помощь!