不能在另一个*.axml文件中包含*.axml文件

isl*_*rid 2 android-layout xamarin.android

我想.axml在另一个.axml使用xamarin android 包含一个文件的布局但是,当我使用<include> 它时不显示任何东西.有什么相当于<include>android在单声道android中,就像下面的链接:

android重用布局

Che*_*ron 11

Xamarin.Android(Android版Mono)或原生Android的XML文件没有区别.该axml扩展纯粹是为了触发VS和Xamarin Studio中的代码完成.Android不关心文件的扩展名.

因此,让我允许显示一个显示<merge><include>标签的示例:

progress_with_text.axml:

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
  <TextView 
    android:text="Loading..."
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:id="@+id/lblLoading" 
    android:layout_marginLeft="180dp"
    android:layout_marginTop="240dp"/>
  <ProgressBar 
    android:id="@+id/progBar"
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content"
    android:layout_marginLeft="130dp"
    android:layout_marginTop="230dp"/>
</merge>
Run Code Online (Sandbox Code Playgroud)

main.axml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <include
        layout="@layout/progress_with_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

这很好用!

  • <merge>标签有什么作用?我是否需要将其包含在任何可重复使用的组件中? (3认同)