Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用<;包括>;在xamarin android中_C#_Android_Xamarin - Fatal编程技术网

C# 使用<;包括>;在xamarin android中

C# 使用<;包括>;在xamarin android中,c#,android,xamarin,C#,Android,Xamarin,我在xamarin中有一个布局,包含两部分:标题和正文 取决于属性,我必须更改标题部分。 我创建了两个布局用作标题部分:header1和header2 我在XamarinAndroid布局中使用了标签,将标题布局添加到主布局中 <include android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentTo

我在xamarin中有一个布局,包含两部分:标题和正文 取决于属性,我必须更改标题部分。 我创建了两个布局用作标题部分:header1和header2 我在XamarinAndroid布局中使用了标签,将标题布局添加到主布局中

<include
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        layout="@layout/header1" />

但是我不能动态地将布局属性更改为header2?

我建议使用,因为您只需要在两个布局之间切换:

.axml


在活动/片段上创建一个私有字段,并在OnCreate方法中对其进行初始化:

private Switcher _headerSwitcher;

//Inside your OnCreate
_headerSwitcher = FindViewById<ViewSwitcher>(Resource.Id.headerSwitcher);
private Switcher\u headerSwitcher;
//在您的OnCreate中
_headerSwitcher=findviewbyd(Resource.Id.headerSwitcher);

然后,您可以使用
\u headerSwitcher.ShowNext()
\u headerSwitcher.ShowPrevious()
在页眉之间进行更改,布局平坦是最佳解决方案:

LayoutInflater inflater = LayoutInflater.From(this);
 View  inflatedLayout = inflater.Inflate(Resource.Layout.yourlayput, null);                  
 LinearLayout ll =  this.Window.FindViewById<LinearLayout>(Resource.Id.container);
ll.AddView(inflatedLayout);
LayoutInflater充气机=LayoutInflater.From(此);
查看充气布局=充气器。充气(Resource.Layout.yourlayput,null);
LinearLayout ll=this.Window.findviewbyd(Resource.Id.container);
ll.添加视图(充气布局);

功能非常好

我只想更改c#中的layout=“@layout/header1”你还有其他解决方案吗?谢谢,它可以工作,但我正在寻找更好的方法,我想做一些类似于usercontrol的事情,我不想像向导一样更改布局。你可以创建自己的视图,然后将此行为封装在其中,但它必须做一些类似的事情(更改可见性或增加新布局),因此此解决方案没有那么大的不同
LayoutInflater inflater = LayoutInflater.From(this);
 View  inflatedLayout = inflater.Inflate(Resource.Layout.yourlayput, null);                  
 LinearLayout ll =  this.Window.FindViewById<LinearLayout>(Resource.Id.container);
ll.AddView(inflatedLayout);