相关疑难解决方法(0)

Android XML Layout的'include'标签真的有用吗?

在Android布局文件中使用<include>时,我无法覆盖属性.当我搜索错误时,我发现了拒绝问题2863:

"包括标签被破坏(覆盖布局参数永远不会起作用)"

由于Romain表明这在测试套件及其示例中有效,因此我必须做错事.

我的项目组织如下:

res/layout
  buttons.xml

res/layout-land
  receipt.xml

res/layout-port
  receipt.xml
Run Code Online (Sandbox Code Playgroud)

buttons.xml包含如下内容:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

  <Button .../>

  <Button .../>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

肖像和横向的receipt.xml文件看起来像:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

  ...

  <!-- Overridden attributes never work. Nor do attributes like
       the red background, which is specified here. -->
  <include
      android:id="@+id/buttons_override"
      android:background="#ff0000"
      android:layout_width="fill_parent"
      layout="@layout/buttons"/>

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

我错过了什么?

android android-widget

84
推荐指数
2
解决办法
3万
查看次数

标签 统计

android ×1

android-widget ×1