R.styleable无法解决

时间:2010-11-26 08:01:47

标签: java android imageview

hai friends ...我的java文件表明此错误: R.styleable无法解决....

我的xml文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical" 
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">

<Gallery xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/videoGrdVw" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:numColumns="auto_fit" 
     android:verticalSpacing="5dip" 
     android:horizontalSpacing="5dip" 
     android:columnWidth="80dip" 
     android:stretchMode="columnWidth" 
     android:gravity="center"/> 

 <ImageSwitcher 

    android:id="@+id/switcher" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent">

    </ImageSwitcher>
    <resources>
    <declare-styleable name="HelloGallery">
    <attr name="android:galleryItemBackground" />
    </declare-styleable>
    </resources>


    </LinearLayout>

源代码:

private class VideoGalleryAdapter extends BaseAdapter
{
     private int itemBackground;

    public VideoGalleryAdapter(Context c) 
    {
        _context = c;
        TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
        itemBackground = a.getResourceId(
                R.styleable.Gallery1_android_galleryItemBackground, 0);
        a.recycle(); 
    }

3 个答案:

答案 0 :(得分:4)

values文件夹下创建一个名为attributes.xml的xml文件,并将内容复制到其中。

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

这应该有用。

答案 1 :(得分:3)

根据这个forum thread你需要改变:

TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);

TypedArray a = c.obtainStyledAttributes(R.styleable.Gallery1);

答案 2 :(得分:-4)

对我来说,这就是诀窍:

import android.R;