本文介绍了我们如何使用Monodroid滑动布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! MAin Activity.cs 使用系统; 使用Android.App; 使用Android。内容; 使用Android.Runtime; 使用Android.Views; 使用Android.Widget; 使用Android.OS; 使用Android.Support.V4.App; 使用Android.Support.V4.View; 命名空间ViewPagerDemo { [活动(标签=ViewPagerDemo,MainLauncher = true)] 公共类MainActivity:FragmentActivity { protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView (Resource.Layout.Main); ViewPager pager =(ViewPager)FindViewById(Resource.Id.viewPager); pager.Adapter = new MyPagerAdapter(this,SupportFragmentManager) ; } 私人课程MyPagerAdapter:FragmentPagerAdapter { 私人阅读nly MainActivity outerInstance; public MyPagerAdapter(MainActivity outerInstance,Android.App.FragmentManager fm):base(fm) { this.outerInstance = outerInstance; } 公共覆盖Android.App.Fragment GetItem(int pos) { 开关(pos) { 案例0: 返回FirstFragment.newInstance(FirstFragment,Instance 1); case 1: 返回SecondFragment.newInstance(SecondFragment,Instance 1); 案例2: 返回ThirdFragment.newInstance(ThirdFragment,Instance 1); 案例3: 返回ThirdFragment.newInstance(ThirdFragment,Instance 2); case 4: 返回ThirdFragment.newInstance(ThirdFragment,Instance 3); 默认值: 返回ThirdFragment.newInstance(ThirdFragment,Default); } } } public int Count { get { 返回5; } } } } Main.Xml < linearlayout的xmlns:机器人= http://schemas.android.com/apk/res/android > android:orientation =vertical android:layout_width =fill_parent android:layout_height =fill_parent> < android .support.v4.view.viewpager> xmlns:android =http://schemas.android.com/apk/res/android xmlns:app = http://schemas.android.com/apk/res-auto android:id =@ + id / viewPager android:layout_width =fill_parent android:layout_height =fill_parent /> FirstFragment.cs 使用System; 使用System.Collections.Generic; 使用System.Linq; 使用System.Text; 使用Android.App; 使用Android.Content; 使用Android.OS; 使用Android.Runtime; 使用Android.Views; 使用Android.Widget; 命名空间ViewPagerDemo { 公共类FirstFragment:Fragment { pub lic override查看OnCreateView(LayoutInflater inflater,ViewGroup容器,Bundle savedInstanceState) { 查看v = inflater.Inflate(Resource.Layout.first_frag,container,false); TextView tv =(TextView)v.FindViewById(Resource.Id.tvFragFirst); tv.Text = Arguments.GetString(msg ); 返回v; } public static FirstFragment newInstance(字符串文本) { FirstFragment f = new FirstFragment(); Bundle b = new Bundle(); b.PutString(msg,text); f.Arguments = b; 返回f; } } } first_frag.xml < relativelayout xmlns:android =http://schemas.android.com/apk/res/android > android:layout_width =match_parent android:layout_height =match_pare nt android:removed =@ android:color / holo_orange_dark> < textview> android:id =@ + id / tvFragFirst android:layout_width =wrap_content android:layout_height =wrap_content android:layout_centerHorizo​​ntal =true android:layout_centerVertical =true android:textSize =26dp android:text =TextView/> SecondFragment.cs 使用系统; 使用System.Collections.Generic; 使用System.Linq; 使用System.Text; 使用Android.App; 使用Android.Content; 使用Android.OS; 使用Android.Runtime; 使用Android.Views; 使用Android.Widget; 命名空间ViewPagerDemo { 公共课SecondFragment:Fragment { public override查看OnCreateView(LayoutInflater inflater,ViewGroup容器,Bundle savedInstanceState) { 查看v = inflater.Inflate(Resource.Layout.second_frag,container, false); TextView tv =(TextView)v.FindViewById(Resource.Id.tvFragSecond); tv.Text =参数。 GetString(msg); 返回v; } public static SecondFragment newInstance(string text) { SecondFragment f = new SecondFragment(); 捆绑b =新捆绑(); b.PutString(msg,text); f.Arguments = b; 返回f; } } } second_frag.xml < relativelayout xmlns:android =http://schemas.android.com/apk/ res / android> android:layout_width =match_parent android:layout_height =ma tch_parent android:removed =@ android:color / holo_green_dark> < textview> android:id =@ + id / tvFragSecond android:layout_width =wrap_content android:layout_height =wrap_content android:layout_centerHorizo​​ntal =true android:layout_centerVertical =true android:textSize =26dp android:text =TextView/> ThirdFragment.cs 使用系统; 使用System.Collections.Generic; 使用System.Linq; 使用System.Text; 使用Android.App; 使用Android.Content; 使用Android.OS; 使用Android.Runtime; 使用Android.Views; 使用Android.Widget; 命名空间ViewPagerDemo { 公共课ThirdFragment:Fragment { 公共覆盖查看OnCreateView(LayoutInflater inflater,ViewGroup容器,Bundle savedInstanceState) { 查看v = inflater.Inflate(Resource.Layout.third_frag ,容器,假); TextView tv =(TextView)v.FindViewById(Resource.Id.tvFragThird); tv.Text = Arguments.GetString(msg); 返回v; } public static ThirdFragment newInstance(string text) { ThirdFragment f = new ThirdFragment(); Bundle b = new Bundle(); b.PutString(msg,text); f.Arguments = b; 返回f; } } } third_frag.xml < relativelayout xmlns:android =http://schemas.android.com / apk / res / android> android:layout_width =match_parent android:layout_height =matc h_parent android:removed =@ android:color / holo_red_light> < textview> android:id =@ + id / tvFragThird android:layout_width =wrap_content android:layout_height =wrap_content android:layout_centerHorizo​​ntal =true android:layout_centerVertical =true android:textSize =26dp android:text =TextView/> 并且它在主要活动中显示出错误 和错误是 ViewPagerDemo.MainActivity.MyPageAdapter没有实现继承的抽象成员Android.Support.V4.App.FragmentPagerAdapter所以让我解决这个问题。MAin Activity.csusing System;using Android.App;using Android.Content;using Android.Runtime;using Android.Views;using Android.Widget;using Android.OS;using Android.Support.V4.App;using Android.Support.V4.View;namespace ViewPagerDemo{[Activity (Label = "ViewPagerDemo", MainLauncher = true)]public class MainActivity : FragmentActivity{protected override void OnCreate (Bundle bundle){base.OnCreate (bundle);SetContentView (Resource.Layout.Main);ViewPager pager = (ViewPager) FindViewById(Resource.Id.viewPager);pager.Adapter = new MyPagerAdapter(this, SupportFragmentManager);} private class MyPagerAdapter : FragmentPagerAdapter { private readonly MainActivity outerInstance;public MyPagerAdapter(MainActivity outerInstance, Android.App.FragmentManager fm) : base(fm){this.outerInstance = outerInstance;}public override Android.App.Fragment GetItem(int pos) {switch (pos) {case 0:return FirstFragment.newInstance("FirstFragment, Instance 1");case 1:return SecondFragment.newInstance("SecondFragment, Instance 1");case 2:return ThirdFragment.newInstance("ThirdFragment, Instance 1");case 3:return ThirdFragment.newInstance("ThirdFragment, Instance 2");case 4:return ThirdFragment.newInstance("ThirdFragment, Instance 3");default:return ThirdFragment.newInstance("ThirdFragment, Default");}}}public int Count{get{return 5;}}}}Main.Xml<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"> android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"><android.support.v4.view.viewpager> xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/viewPager" android:layout_width="fill_parent" android:layout_height="fill_parent" />FirstFragment.csusing System;using System.Collections.Generic;using System.Linq;using System.Text;using Android.App;using Android.Content;using Android.OS;using Android.Runtime;using Android.Views;using Android.Widget;namespace ViewPagerDemo{ public class FirstFragment : Fragment {public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {View v = inflater.Inflate(Resource.Layout.first_frag, container, false);TextView tv = (TextView) v.FindViewById(Resource.Id.tvFragFirst);tv.Text = Arguments.GetString("msg");return v; }public static FirstFragment newInstance(string text) {FirstFragment f = new FirstFragment();Bundle b = new Bundle();b.PutString("msg", text);f.Arguments = b;return f; } }}first_frag.xml<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"> android:layout_width="match_parent" android:layout_height="match_parent" android:removed="@android:color/holo_orange_dark"> <textview> android:id="@+id/tvFragFirst" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:textSize="26dp" android:text="TextView" />SecondFragment.csusing System;using System.Collections.Generic;using System.Linq;using System.Text;using Android.App;using Android.Content;using Android.OS;using Android.Runtime;using Android.Views;using Android.Widget;namespace ViewPagerDemo{ public class SecondFragment : Fragment{public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){View v = inflater.Inflate(Resource.Layout.second_frag, container, false);TextView tv = (TextView) v.FindViewById(Resource.Id.tvFragSecond);tv.Text = Arguments.GetString("msg");return v;}public static SecondFragment newInstance(string text){SecondFragment f = new SecondFragment();Bundle b = new Bundle();b.PutString("msg", text);f.Arguments = b;return f;} }}second_frag.xml<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"> android:layout_width="match_parent" android:layout_height="match_parent" android:removed="@android:color/holo_green_dark"> <textview> android:id="@+id/tvFragSecond" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:textSize="26dp" android:text="TextView" />ThirdFragment.csusing System;using System.Collections.Generic;using System.Linq;using System.Text;using Android.App;using Android.Content;using Android.OS;using Android.Runtime;using Android.Views;using Android.Widget;namespace ViewPagerDemo{public class ThirdFragment : Fragment{public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){View v = inflater.Inflate(Resource.Layout.third_frag, container, false);TextView tv = (TextView) v.FindViewById(Resource.Id.tvFragThird);tv.Text = Arguments.GetString("msg");return v;}public static ThirdFragment newInstance(string text){ThirdFragment f = new ThirdFragment();Bundle b = new Bundle();b.PutString("msg", text);f.Arguments = b;return f;} }}third_frag.xml<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"> android:layout_width="match_parent" android:layout_height="match_parent" android:removed="@android:color/holo_red_light"> <textview> android:id="@+id/tvFragThird" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:textSize="26dp" android:text="TextView" />AND IT IS SHOWING ERROR IN MAINACTIVITYAND THE ERROR IS "ViewPagerDemo.MainActivity.MyPageAdapter does not implement inherited abstract member Android.Support.V4.App.FragmentPagerAdapter" so Plzz Let Me Out Of this Problem.推荐答案 这篇关于我们如何使用Monodroid滑动布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-23 09:53
查看更多