安卓你好,画廊教程 - " R.styleable解决不了" [英] Android Hello, Gallery tutorial -- "R.styleable cannot be resolved"

查看:104
本文介绍了安卓你好,画廊教程 - " R.styleable解决不了"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的说明工作的你好,画廊教程/示例应用程序时,在网站上,Eclipse的报道,R.styleable无法得到解决。

什么是这个错误的原因,以及它如何被固定或合作周围?

解决方案

这个线程,R.styleable已经从安卓1.5及更高版本中删除。

有多种方式来获得样品来工作​​,即我发现的最简单的是在连接到上述螺纹推荐由Justin安德森:

  1. 创建了一个名为resources.xml中包含以下内容的新的XML文件:

     < XML版本=1.0编码=UTF-8&GT?;
    <资源>
        <申报,设置样式名称=Gallery1>
            < attr指示名=机器人:galleryItemBackground/>
        < /申报,设置样式>
    < /资源>
     

  2. 将在资源XML文件\值目录(旁边的strings.xml)

  3. 更​​新构造的ImageAdapter具有以下(假设ImageAdapter类是在它自己的文件中定义):

     公共ImageAdapter(上下文C){
        mContext = C;
        TypedArray A = c.obtainStyledAttributes(R.styleable.Gallery1);
        mGalleryItemBackground = a.getResourceId(R.styleable.Gallery1_android_galleryItemBackground,0);
        a.recycle();
    }
     

该解决方案基本上确定了设置样式属性的应用程序本身的资源,并赋予它必要的结构,在应用程序工作。请注意,应用程序可以运行得很好,如果你只是省略了两行code(之前a.recycle();),这一切都code也被设置在周围的画廊图像的灰色背景<。 / P>

When working on the Hello, Gallery tutorial/sample app, after following the instructions on the site, Eclipse reported that R.styleable cannot be resolved.

What is the reason for this error, and how can it be fixed or worked around?

解决方案

Per this thread, R.styleable has been removed from android 1.5 and higher.

There are a number of ways to get the sample to work, the simplest that I found was recommended by Justin Anderson in the thread linked to above:

  1. Create a new XML file called "resources.xml" with the following content:

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

  2. Place the XML file in the res\values directory (alongside strings.xml)

  3. Update the constructor for your ImageAdapter with the following (assuming the ImageAdapter class is defined in its own file):

    public ImageAdapter(Context c) {
        mContext = c;
        TypedArray a = c.obtainStyledAttributes(R.styleable.Gallery1);
        mGalleryItemBackground = a.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 0);
        a.recycle();
    }
    

This solution basically defines the styleable attribute as a resource of the app itself and gives it the necessary structure to work in the app. Note that the app can run fine if you just omit the two lines of code (prior to a.recycle();), all this code does is set a grey background around the images in the Gallery.

这篇关于安卓你好,画廊教程 - &QUOT; R.styleable解决不了&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆