相关疑难解决方法(0)

Android中"@ id /"和"@ + id /"之间的区别

什么是@id/@+id/?之间的差异?

@+id/加号中+指示创建一个新的资源名称并添加到该R.java文件但是怎么样@id/?从以下文档ID:引用Android资源时ID,您不需要加号,但必须添加android包命名空间,如下所示:

android:id="@android:id/list"
Run Code Online (Sandbox Code Playgroud)

但是在下面的图像中,Eclipse没有提出任何建议@android:id/.

显示@/id和@ +/id建议的图像

@id/@android:id/一样吗?

android android-xml

443
推荐指数
8
解决办法
21万
查看次数

"找不到资源"使用<include layout ="">时

在我的项目中,我创建了一个全局标题布局,global_header.xml并使用它在我的所有布局XML文件中使用它<include layout="@layout/global_header.xml">.

我之前使用过这种方法,目前我在这个项目中使用它.我的问题是我有一个包含以下内容的布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFFFFFFF" >

    <include layout="@layout/global_header" />

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@id/global_header">

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >
        </RelativeLayout>
    </ScrollView>

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

内容global_header.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/global_header"
    android:layout_width="fill_parent"
    android:layout_height="60sp"
    android:layout_alignParentTop="true"
    android:background="#FFDDDDDD" >

    <ImageView
        android:id="@+id/global_header_logo"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5sp"
        android:layout_marginTop="5sp"
        android:adjustViewBounds="true"
        android:src="@drawable/header" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="1sp"
        android:layout_alignParentBottom="true"
        android:background="#FF000000" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

我说错了android:layout_below="@global/header":

错误:错误:找不到与给定名称匹配的资源(在'layout_below'中,值为'@ global/header').

我在项目中的其他布局中使用了include,它没有问题,但无论出于何种原因,此布局文件都不会像所有其他布局那样从标题中加载ID.

该项目不会构建此错误,即使我确信一旦在设备上运行它会发现它不是问题,还有其他人有这个问题吗?有解决方案/解决方法吗?

非常感谢任何和所有的帮助.

xml layout android include

2
推荐指数
1
解决办法
2089
查看次数

布局导致App崩溃

所以我一直试图改变我的几个xmls中的布局,但出于某种原因,当我改变这个时,它会崩溃应用程序.新布局如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" 
android:background="@drawable/gradient_bg" >
<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="center" >

</RelativeLayout>
<!-- Footer aligned to bottom -->
<RelativeLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
 <Button
    android:id="@+id/ButtonOK"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1" 
    android:layout_toLeftOf="@+id/ButtonAll"
    android:text="Go"
    style="@style/btnStyleBreakerBay"/>
    <Button
    android:id="@+id/ButtonAll"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1" 
    android:text="See All"
    android:layout_toRightOf="@+id/ButtonOK"
    android:layout_toLeftOf="@+id/ButtonBack"
    style="@style/btnStyleBreakerBay"/>
    <Button
    android:id="@+id/ButtonBack"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1" 
    android:text="Back"
    android:layout_toRightOf="@+id/ButtonAll"
    style="@style/btnStyleBreakerBay"/>
</RelativeLayout>
<ScrollView
android:id="@+id/scrollableContents"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@id/footer"
android:layout_below="@id/header" >
    <LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    >
<TextView android:id="@+id/typeEvent"
android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Type of Event:"
    android:visibility="gone"
    style="@style/black_text"/>

        <Spinner
    android:id="@+id/spinner_search_event" …
Run Code Online (Sandbox Code Playgroud)

xml layout android

1
推荐指数
1
解决办法
807
查看次数

标签 统计

android ×3

layout ×2

xml ×2

android-xml ×1

include ×1