hai friends...my 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();
}发布于 2011-02-03 05:21:23
对我来说,这就是诀窍:
import android.R;发布于 2013-09-05 15:11:29
在values文件夹下创建一个名为attributes.xml的xml文件,并将下面的内容复制到其中。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="Gallery1">
<attr name="android:galleryItemBackground"/>
</declare-styleable>
</resources>这应该是可行的。
发布于 2010-11-26 16:15:17
根据此forum thread,您需要更改:
TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);至
TypedArray a = c.obtainStyledAttributes(R.styleable.Gallery1);https://stackoverflow.com/questions/4283455
复制相似问题