关于android R文件丢失的问题,详情请看截图

图片说明网上的各种方法基本试过了搞了好久都不行,请大神指点!!!下面是布局

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:keepScreenOn="true"
    android:orientation="vertical"
    android:fitsSystemWindows="false">

    <RelativeLayout
        android:id="@+id/cortex_scanner_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        android:layout_marginLeft="0dp"
        android:layout_marginRight="0dp"
        android:layout_marginTop="0dp"
        android:layout_marginBottom="0dp">

        <!--
            This view will be inserted by CortexScan.onCreate().

                <com.codecorp.cortex_scan.CameraPreview />
         -->

        <com.hongshan.myapplication.CrosshairsView
            android:id="@id/crosshairs_view"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:onClick="resetContinuousScan"/>

        <android.support.percent.PercentRelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <com.hongshan.myapplication.PicklistView
                android:id="@+id/picklist_view"
                android:layout_width="0dp"
                app:layout_widthPercent="87%"
                android:layout_height="24dp"
                android:layout_centerInParent="true"
                android:onClick="resetContinuousScan"/>



        </android.support.percent.PercentRelativeLayout>

        <TextView
            android:id="@+id/tap_to_scan_again"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:background="#c0000000"
            android:clickable="false"
            android:padding="10dp"
            android:text="@string/tap_to_scan_again"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#FFFFFF"
            android:visibility="invisible"
            android:layout_centerInParent="true" />
    </RelativeLayout>

    <ImageView
        android:id="@+id/code_corp_logo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:src="@drawable/code_logo"
        android:contentDescription="@string/code_corp_logo"
        android:paddingTop="10dp" />

    <ImageView
        android:id="@+id/settingsButton"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="30dp"
        android:layout_marginRight="20dp"
        android:layout_marginEnd="20dp"
        android:src="@mipmap/ic_menu_settings_white"
        android:contentDescription="@string/settings_desc"
        android:onClick="onSettingsClicked" />

    <ImageView
        android:id="@+id/infoButton"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_toLeftOf="@id/settingsButton"
        android:layout_toStartOf="@id/settingsButton"
        android:layout_alignTop="@id/settingsButton"
        android:layout_marginRight="20dp"
        android:layout_marginEnd="20dp"
        android:src="@android:drawable/ic_dialog_info"
        android:contentDescription="@string/info"
        android:onClick="onInfoClicked" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/image_capture"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:visibility="invisible"
        android:onClick="captureImage"
        android:src="@drawable/image_capture_selector"
        android:paddingRight="20dp"/>


<!--    <TextView
        android:id="@id/demo_text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/info_bar"
        android:gravity="center"
        android:paddingBottom="0dp"
        android:text=""
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#FFFFFF" />-->

    <RelativeLayout
        android:id="@+id/info_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/background_gradient"
        android:layout_alignParentBottom="true"
        android:paddingBottom="0dp">

        <GridLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="2dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:paddingTop="0dp"
            android:rowCount="3"
            android:columnCount="2">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingRight="10dp"
                android:paddingLeft="10dp"
                android:layout_row="0"
                android:layout_column="0"
                android:text="@string/barcode_colon"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#FFFFFF" />

            <TextView
                android:id="@+id/barcode_result"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_row="0"
                android:layout_column="1"
                android:ellipsize="end"
                android:maxLines="2"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#FFFFFF" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_row="1"
                android:layout_column="0"
                android:paddingRight="10dp"
                android:paddingLeft="10dp"
                android:text="@string/length_colon"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#FFFFFF" />

            <TextView
                android:id="@+id/length_result"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_row="1"
                android:layout_column="1"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#FFFFFF" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_row="2"
                android:layout_column="0"
                android:paddingRight="10dp"
                android:paddingLeft="10dp"
                android:text="@string/symbology_colon"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#FFFFFF" />

            <TextView
                android:id="@+id/symbology_result"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_row="2"
                android:layout_column="1"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#FFFFFF" />
        </GridLayout>

        <ImageView
            android:id="@+id/scanButton"
            android:layout_width="220dp"
            android:layout_height="100dp"
            android:layout_centerHorizontal="true"
            app:layout_widthPercent="33%"
            android:paddingBottom="0dp"
            android:src="@drawable/button_background_tablet_selector"
            android:contentDescription="@string/scan_button_desc"
            android:onClick="onScanClicked" />

    </RelativeLayout>

</RelativeLayout>

如果是用android studio开发,build->Rebuild Project 有效果,我之前是这样解决红线问题的

这个问题好像是你在xml中使用的view没有这两个属性方法引起的吧

布局文件有错,ID命名不规范或者控件属性错误会导致R文件消失

你查看一下你的布局,Android Studio对应的不是有布局的显示吗?如果不显示就是你的布局有误。

https://segmentfault.com/q/1010000008193819
老铁,这个试一下~

代码有问题 或者布局文件有错

在你的main_view.xml中 将
xmlns:app="http://schemas.android.com/apk/res-auto" 改为
xmlns:appCompat="http://schemas.android.com/apk/res-auto"