我遇到了同样的问题——当我想在 XML 文件中添加 id LinearLayout 时,Eclipse 说文件构建正确——但组件 ID 不可用——它没有添加到文件 R.java 中。也许这是因为对于给定的组件指定了警告“此 LinearLayout 布局或其 TableRow 父级可能无用”这一事实?我怎么解决这个问题?我希望能得到你的帮助。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:gravity="center"
android:background="#E8E8E8" >
<TableLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:orientation = "vertical"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content">
<TableRow
android:id="@+id/base_table_row1"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:paddingTop = "15dp"
android:paddingBottom = "15dp"
android:gravity = "center">
<TextView
android:id="@+id/name_placeView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="name of the place"
android:gravity="center"
android:textStyle="bold"
android:textColor="#000000"
android:textSize="30sp"/>
</TableRow>
<TableRow
android:id = "@+id/base_table_row3"
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:gravity = "center">
<TextView
android:id="@+id/info_placeView"
android:textColor="#808080"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="adress"/>
</TableRow>
<TableRow
android:id = "@+id/base_table_row2"
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:paddingBottom = "15dp"
android:gravity = "center">
<TextView
android:id="@+id/info_placeView"
android:layout_width="wrap_content"
android:textColor="#808080"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:layout_height="wrap_content"
android:text="There will be placed an short information about place"/>
</TableRow>
<TableRow
android:id = "@+id/base_table_row3"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:paddingTop = "15dp"
android:gravity = "center">
<TextView
android:id="@+id/comfortView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:textColor="#DAA520"
android:text="Atmosphear"/>
</TableRow>
<TableRow
android:id = "@+id/base_table_row4"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:gravity = "center">
<LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:orientation = "vertical"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:gravity="center">
<RatingBar
android:id="@+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="1.0" />
</LinearLayout>
</TableRow>
<TableRow
android:id = "@+id/base_table_row5"
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:paddingTop = "15dp"
android:gravity = "center">
<TextView
android:id="@+id/priceView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:textColor="#DAA520"
android:text="Peoplemeter" />
</TableRow>
<TableRow
android:id = "@+id/base_table_row6"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:gravity = "center">
<LinearLayout
xmlns:android = "http://schemas.android.com/apk/res/android"
android:id="@+id/layout_rate_bar2"
android:orientation = "vertical"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:gravity="center">
<RatingBar
android:numStars="5"
android:id="@+id/ratingBar2"
android:stepSize="1.0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</TableRow>
<TableRow
android:id = "@+id/base_table_row7"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:paddingTop = "20dp"
android:gravity = "center"
>
<LinearLayout
android:id = "@+id/final_rate_layout"
android:orientation = "vertical"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:gravity="center"
>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@drawable/button_custom_rate"
android:textStyle="bold"
android:textSize="20sp"
android:text="RATE IT"
android:id="@+id/final_rate"
android:clickable="true"
/>
</LinearLayout>
</TableRow>
</TableLayout>
</LinearLayout>