【问题标题】:R.styleable cannot be resolvedR.styleable 无法解决
【发布时间】:2011-05-16 01:40:28
【问题描述】:

hai 朋友...我的 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(); 
    }

【问题讨论】:

标签: java android imageview


【解决方案1】:

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

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

这应该可行。

【讨论】:

  • 感谢骑士你的想法帮助了我:)
【解决方案2】:

根据这个forum thread你需要改一下:

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

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

【讨论】:

  • 阅读完整的主题,看看是否有其他想法。另外,不要接受答案,除非它真的解决了你的问题。这将使该问题的未来读者感到困惑。
  • 确保你明确地导入你的 R 类
【解决方案3】:

对我来说,这成功了:

import android.R;

【讨论】:

猜你喜欢
  • 2011-10-04
  • 1970-01-01
  • 2018-06-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-11
  • 1970-01-01
  • 2016-03-30
  • 2018-04-21
相关资源
最近更新 更多