آموزش های این وب سایت به صورت رایگان در دسترس است. اطلاعات بیشتر
بروز خطا
   [message]
اشتراک در سوال
رای ها
[dataList]

کد مربوط به gallery در کتاب "مرجع کامل برنامه نویسی در اندروید" میشه کسی توضیح بده؟

ebrahim_rayaneh  11 سال پیش  11 سال پیش
+1 0

در کتاب مرجع کامل برنامه نویسی در اندروید  در اوایل فصل 5 اش در مورد گالری و ایمیج ویو نوشته اما توضیحات خیلی گنگ و نامفهوم هستند ، در سایت استک اورفلو هم راجب بهش نوشتن اما چون انگلیسی من ضعفیه زیاد سر درنیاوردم چی نوشتن... پس از ارجاع دادن من به اون سایت جدا خودداری کنید! مخصوصا اون فایل xml  خیلی گنگ هست... مثلا این تگ declare-styleable برا چی هست؟ یا این یکی چی: attr name=”android:galleryItemBackground” ، یا تو کلاس جاوا : R.styleable.Gallery1 ؟

این دستور R.styleable.Gallery1_android_galleryItemBackground چطور ؟ اگه کسی بتونه کلا در مورد این کدها توضیحاتی بده ممنون میشم.

اما کدها:

res/values/attrs.xml

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


 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; 
        }
    }
}
 برای این سوال پاسخی وجود ندارد.

پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .