R不生成按钮

时间:2013-12-26 10:45:48

标签: android

我刚刚完成了我想要的布局,即使我保存了所有内容,当我尝试通过id找到按钮时,我正在寻找的按钮丢失了..这两个按钮我都有...我在ID下检查了R类,看起来它没有看到'按钮。不生成它们?我不知道..无论如何,每当我使用相对布局时都会发生!有联系吗?它适用于TableLayout和线性布局..只有相对布局才会产生问题。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/Background" >

<TextView
    android:id="@+id/corpTag"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:text="@string/corpTag"
    android:textColor="@color/White" />

<Button
    android:id="@+id/addBusinessButton"
    style="@android:style/ButtonBar"
    android:layout_width="200dp"
    android:layout_height="25dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="208dp"
    android:text="@string/addYourBusiness" />

<Button
    android:id="@+id/searchBusinessButton"
    style="@android:style/ButtonBar"
    android:layout_width="200dp"
    android:layout_height="25dp"
    android:layout_alignBottom="@+id/addBusinessButton"
    android:layout_alignLeft="@+id/addBusinessButton"
    android:layout_marginBottom="36dp"
    android:text="@string/searchBusiness" />

3 个答案:

答案 0 :(得分:1)

我发现这种情况发生在布局上。不用担心。我正尽力为你提供解决方案

<强>解决方案

确保 R。链接的所有内容均未损坏。修复XML文件中的所有错误。如果ADK中的任何内容被破坏,R将不会重新生成。

如果您以某种方式点击某些内容并在您的活动中创建了导入android.R,请将其删除。 运行项目 - &gt;清理。这将删除并重新生成R和BuildConfig。

确保项目 - &gt;勾选自动生成。如果没有,请通过菜单 - &gt;手动构建它。项目 - &gt;建立项目。

等几秒钟让错误消失。

答案 1 :(得分:0)

它可能是Android Style ButtonBar。它不适用于每个API级别。因此,如果您的minSDK较低,则不会构建,Eclipse / IntelliJ应在其错误窗格中显示错误消息。

Google提供的规则是,您应该始终定义自己的资源。如果你想使用Android名称空间中的资源,那很好,但是你应该先复制它并将它与你的apk一起打包,因为这是你可以放心它总是与你的应用程序捆绑在一起的唯一方法。

是的,我意识到很多人和网上的许多教程都不这样做,但这是因为大多数人都很懒惰。

答案 2 :(得分:0)

此问题与相对布局无关,但实际上是在后台设置的,因为Android drwable区分大小写,现在允许使用大写字母表示图像或布局。将您的图像名称或可drwable名称重命名为“background”而不是Background。“

以下是设置背景名称的问题:

android:background="@drawable/Background"