0x01 前言

相信对于用过Android版QQ的,应该都不会陌生它那个向右滑动的菜单(虽说我用的是Lumia)

今天就用Xamarin.Android实现个比较简单的抽屉布局。下面直接进正题。

0x02 做个简单的抽屉布局

新建个android项目

通过NuGet安装个Xamarin.Android.Support.v4

%E5%A4%96%E9%93%BE%E7%BD%91%E5%9D%80%E5%B7%B2%E5%B1%8F%E8%94%BD

其实呢,官网那里还用很多组件可用拿来尝试一下的。

然后修改Main.axml

1 <?xml version="1.0" encoding="utf-8"?>

2

3 android:layout_width="match_parent"

4 android:layout_height="match_parent">

5

7 android:layout_width="match_parent"

8 android:layout_height="match_parent">

9

11 android:layout_width="match_parent"

12 android:layout_height="match_parent" />

13

15 android:layout_width="200dp"

16 android:layout_height="match_parent"

17 android:layout_gravity="start"

18 android:background="@android:color/holo_blue_light"

19 android:choiceMode="singleChoice"

20 android:divider="@android:color/transparent"

21 android:dividerHeight="0dp" />

22

23

这里用了相对布局,更重要的是android.support.v4.widget.DrawerLayout

同时新建一个fragmentcontent.axml,用于呈现选中菜单的内容。

1 <?xml version="1.0" encoding="utf-8"?>

2

3 android:orientation="vertical"

4 android:layout_width="match_parent"

5 android:layout_height="match_parent">

6

8 android:layout_height="match_parent"

9 android:gravity="center"

10 android:textAlignment="center"

11 android:textSize="30dp"

12 android:id="@+id/txtName" />

13

内容比较简单,就是显示相应菜单的文本。

然后,修改MainActivity

1 usingAndroid.App;2 usingAndroid.OS;3 usingAndroid.Support.V4.Widget;4 usingAndroid.Widget;5 namespaceDrawerLayoutDemo6 {7 [Activity(Label = "DrawerLayoutDemo", MainLauncher = true, Icon = "@drawable/icon")]8 public classMainActivity : Activity9 {10 private string[] _menu;11 protected override voidOnCreate(Bundle bundle)12 {13 base.OnCreate(bundle);14

15 SetContentView(Resource.Layout.Main);16 //the menu

17 _menu = new string[] { "C#", "Python", "Xamarin"};18 //listview

19 var listView = FindViewById(Resource.Id.left_drawer);20 //adapter

21 listView.Adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, _menu);22 //drawerlayout

23 var drawerLayout = FindViewById(Resource.Id.mDrawerLayout);24 //click event

25 listView.ItemClick +=ItemClick;26 }27 ///

28 ///item click event of the listview29 ///

30 ///

31 ///

32 private void ItemClick(objectsender, AdapterView.ItemClickEventArgs e)33 {34 //fragment

35 Fragment fragment = newFragmentContent(_menu[e.Position]);36 //show

37 var fm =FragmentManager.BeginTransaction().Replace(Resource.Id.content_frame, fragment).Commit();38 }39 }40 }

MainActivity的话主要是处理ListView的绑定以及点击事件。

新建一个FragmentContent

1 usingAndroid.App;2 usingAndroid.OS;3 usingAndroid.Views;4 usingAndroid.Widget;5 namespaceDrawerLayoutDemo6 {7 public classFragmentContent : Fragment8 {9 private string_text;10 public FragmentContent(stringtext)11 {12 _text =text;13 }14 public override voidOnCreate(Bundle savedInstanceState)15 {16 base.OnCreate(savedInstanceState);17 }18

19 public overrideView OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)20 {21 //get the view

22 View view = inflater.Inflate(Resource.Layout.fragmentcontent, null);23 var txt = view.FindViewById(Resource.Id.txtName);24 //set the text of the textview

25 txt.Text = "I Love" +_text;26 returnview;27 }28 }29 }

Fragment的话,就是显示把fragmentcontent.axml显示,把菜单的值显示出来。

到这里,功能是已经完成了,但是呢,是不是就能成功运行呢?

问题还是有的!!发布的时候,出现下面的问题。

1>C:\Program Files (x86)\MSBuild\Xamarin\Android\mon.targets(348,2): error XA5208: Download failed. Please download 外链网址已屏蔽 and put it to the C:\Users\Catcher\AppData\Local\Xamarin\Android.Support.v4\23.3.0.0 directory.

1>C:\Program Files (x86)\MSBuild\Xamarin\Android\mon.targets(348,2): error XA5208: Reason: One or more errors occurred.

1>C:\Program Files (x86)\MSBuild\Xamarin\Android\mon.targets(348,2): error XA5207: Please install package: 'Xamarin.Android.Support.v4' available in SDK installer. Java library file C:\Users\Catcher\AppData\Local\Xamarin\Android.Support.v4\23.3.0.0\embedded\classes.jar doesn't exist.

1>C:\Program Files (x86)\MSBuild\Xamarin\Android\mon.targets(348,2): error XA5208: Download failed. Please download 外链网址已屏蔽 and put it to the C:\Users\Catcher\AppData\Local\Xamarin\Android.Support.v4\23.3.0.0 directory.

1>C:\Program Files (x86)\MSBuild\Xamarin\Android\mon.targets(348,2): error XA5208: Reason: One or more errors occurred.

1>C:\Program Files (x86)\MSBuild\Xamarin\Android\mon.targets(348,2): error XA5207: Please install package: 'Xamarin.Android.Support.v4' available in SDK installer. Java library file C:\Users\Catcher\AppData\Local\Xamarin\Android.Support.v4\23.3.0.0\embedded\libs/internal_impl-23.3.0.jar doesn't exist.

下面给出解决方案。

0x03 出错处理方案

从错误我们能看出缺少东西了。

其实这个文件是可以直接下载的,不用FQ。但是在生成或是发布的时候下载会出错。

在C:\Users\Catcher\AppData\Local\Xamarin\zips下面(这个是下载之后所在的目录)

%E5%A4%96%E9%93%BE%E7%BD%91%E5%9D%80%E5%B7%B2%E5%B1%8F%E8%94%BD

这个zip文件一直是处于无效的状态。所以只能单独下载上面的那个文件,然后把文件放在

zips那个目录下面,同时改为这个名字,即可。

然后再生成就不会出现问题了。

同时它会在C:\Users\Catcher\AppData\Local\Xamarin\Android.Support.v4\23.3.0.0目录下生成下面两个文件夹

%E5%A4%96%E9%93%BE%E7%BD%91%E5%9D%80%E5%B7%B2%E5%B1%8F%E8%94%BD

0x04 效果图

%E5%A4%96%E9%93%BE%E7%BD%91%E5%9D%80%E5%B7%B2%E5%B1%8F%E8%94%BD

当然,这个demo简单到不行,想弄好看点的话就自己自定义listview的样式

文字旁边个图标之类的。。然后写个好看的布局。。

最后推荐马跃大哥的博客,学Xamarin.Android可以去看看

android底部抽屉库,Xamarin.Android之简单的抽屉布局相关推荐

  1. Android系统运行库分为,Android系统架构

    Android系统架构可分为五层,从上到下依次是应用层.应用框架层.系统运行时库层.硬件抽象层和Linux内核层 应用层 (System Apps) 系统内置的应用程序以及非系统级应用程序都属于应用层 ...

  2. android 底部加载更多,android:ScrollView滑动到底部显示加载更多(示例代码)

    这是效果 主要是onTouchListener监听事件,监视什么时候滑到底部 同时要理解getMeasuredHeight和getHeight的区别 getMeasuredHeight:全部的长度 包 ...

  3. android自动启动无障碍服务,Xamarin.Android:如何开启无障碍服务永久

    我写的辅助服务,以避免USSD请求过程中AlertWindow开幕:Xamarin.Android:如何开启无障碍服务永久 [Service(Label = "BalanceAccessib ...

  4. Android底部日期控件,Android开发中实现IOS风格底部选择器(支持时间 日期 自定义)...

    本文Github代码链接 先上图吧: 这是笔者最近一个项目一直再用的一个选择器库,自己也在其中做了修改,并决定持续维护下去. 先看使用方法: 日期选择: private void showDateDi ...

  5. android底部滑出view,Android CoordinatorLayout与NestedScrollView基于Behavior几行代码实现底部View滑入滑出...

    Android CoordinatorLayout与NestedScrollView基于Behavior几行代码实现底部View滑入滑出 在CoordinatorLayout的Behavior出现之前 ...

  6. 2020年度整理国内一线互联网公司内部Android面试题库,android网络文件下载

    B反馈给A表示正确收到消息 B发送消息给A A反馈给B表示正确收到消息. 但是连接中,第二步和第三步是可以合并的,因为连接之前A和B是无联系的,所以没有其他情况需要处理.而断开的话,因为之前两端是正常 ...

  7. android通用ui库设计,Android(常用)主流UI开源库整理

    这几天刚做完一个项目..有点空余时间,就想着吧这一两年做的项目中的UI界面用到的一些库整理一下.后来想了一下,既然要整理,就把网上常用的 AndroidUI界面的主流开源库一起整理一下,方便查看. 这 ...

  8. android底部tab页动画,Android仿微信底部实现Tab选项卡切换效果

    在网上看了比较多的关于Tab的教程,发现都很杂乱.比较多的用法是用TitlePagerTabStrip和ViewPaper.不过TitlePagerTabStrip有个很大的缺陷,Tab里面的内容刚进 ...

  9. android studio密钥库口令,Android应用开发Android Studio签名打包及根据keystore密钥获取SHA1安全码...

    本文将带你了解Android应用开发Android Studio签名打包及根据keystore密钥获取SHA1安全码,希望本文对大家学Android有所帮助. " 一.签名打包两种方式 1. ...

  10. android安装包大小,xamarin Android 安装包大小的理解

    版本包 若要提供完全包含的应用程序,包必须包含应用程序.关联库.内容.Mono 运行时以及所需的基类库 (BCL) 程序集. 例如,如果我们使用默认的"Hello World"模板 ...

最新文章

  1. 美国 AI 博士:什么都不会怎么学 Python?
  2. python学习路线-Python最佳学习路线
  3. SDK,JDK,API的区别
  4. 【noi 2.6_9284】盒子与小球之二(DP)
  5. 51Nod 1640 - 天气晴朗的魔法(最小生成树变形)
  6. 【转载】关于错误:ASP.NET The URL-encoded form data is not valid. .
  7. 理解TCP的通信原理及IO阻塞
  8. Android小数和整数相互转换
  9. Python--day26--复习
  10. 工作153:position使用
  11. C++ 与Qt开发人机象棋(第一部分)
  12. mysql管理器源码_一个HelloWorld版的MySQL数据库管理器的设计与实现(源码)
  13. GenePix Pro 3.0
  14. Win2008配置终端服务网络负载平衡实战 -2
  15. HTML实现选择数据库字段,django项目中在后台获取了数据库的某一列,如何将其显示在html模板中的select标签内的option选项下?...
  16. linux 常见的挂载命令 mount showmount umount
  17. css实现返回顶部,实现返回顶部效果
  18. 大楼通信综合布线系统_综合布线系统设计方案时需要注意的事项
  19. Day11:麦卡锡91函数(McCarthy 91)
  20. 操作系统原理实验(3):操作系统的基石中断与异常

热门文章

  1. 中文汉字和英文数字的unicode编码范围
  2. golang学习笔记(6)-gorm实现查询功能
  3. 小白学习iOS开发都需要有什么基础
  4. 赵聪慧 java_专家引领,筑梦前行——赵聪慧省名班主任工作室
  5. 【新知实验室】体验腾讯云音视频
  6. #49:Photoshop技巧的大杂烩
  7. android 平板怎么截图,平板电脑怎样截图
  8. 正态总体均值假设检验
  9. EditPlus安装步骤
  10. mysql插入微信名称中的特殊字符