java - R.styleable无法解析

标签 java android imageview

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

最佳答案

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

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

这应该有效。

关于java - R.styleable无法解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4283455/

相关文章:

Android ImageAdapter 设置图像资源

java - 在 Java Eclipse AWT 中,如何检测在按住 Shift 的同时是否单击了按钮?

android - 无法从 Fragment 中的 ViewModel 观察 LiveData

android - 如何从Android相机获取缩略图和图像路径?

java - 带有注解的 GSON 自定义序列化

android - 使用重力 : top 在 ImageView 中定位图像

java - 用imageview线性布局覆盖textview

Java 可选 orElse

java - 当业务逻辑和数据层似乎重叠时,用于分解业务逻辑和数据层的最佳设计?

java - Smb版本2升级问题