以下问题让我困惑了一段时间,我想也许会问这不会有害.我有以下layout.xml和style.xml文件;
RES /布局/ layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
style="@style/headerContainer" />
<LinearLayout
style="@style/footerContainer" />
<ScrollView
style="@style/contentContainer" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
RES /值/ style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="container">
<item name="android:layout_width">fill_parent</item>
</style>
<style name="headerContainer" parent="container">
<item name="android:layout_height">40dp</item>
<item name="android:layout_alignParentTop">true</item>
<item name="android:background">#80FF0000</item>
<item name="android:id">@+id/header</item>
</style>
<style name="footerContainer" parent="container">
<item name="android:layout_height">50dp</item>
<item name="android:layout_alignParentBottom">true</item>
<item name="android:background">#8000FF00</item>
<item name="android:id">@+id/footer</item>
</style>
<style name="contentContainer" parent="container">
<item name="android:layout_height">60dp</item>
<item name="android:layout_below">@id/header</item>
<item name="android:layout_above">@id/footer</item>
<item name="android:background">#800000FF</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
现在,问题是,当我在style.xml中引入ID时,是否存在重叠ID的危险?有趣的是,这种方法在我至少使用的模拟器上有效,但创建的ID没有被添加到R类中.一旦我的布局膨胀,我对它们的定义有点困惑.