首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法解析R.styleable

无法解析R.styleable
EN

Stack Overflow用户
提问于 2010-11-26 16:01:47
回答 3查看 9.9K关注 0票数 2

hai friends...my java文件指示此错误:无法解析R.styleable ...

我的xml文件:

代码语言:javascript
复制
<?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>

源代码:

代码语言:javascript
复制
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(); 
    }
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-02-03 05:21:23

对我来说,这就是诀窍:

代码语言:javascript
复制
import android.R;
票数 -4
EN

Stack Overflow用户

发布于 2013-09-05 15:11:29

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

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="Gallery1">
        <attr name="android:galleryItemBackground"/>
    </declare-styleable>
</resources>

这应该是可行的。

票数 4
EN

Stack Overflow用户

发布于 2010-11-26 16:15:17

根据此forum thread,您需要更改:

代码语言:javascript
复制
TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);

代码语言:javascript
复制
TypedArray a = c.obtainStyledAttributes(R.styleable.Gallery1);
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4283455

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档