![]() ![]() 它应类似于以下屏幕截图:It should look like the screenshot below: I.LayoutParameters = new Gallery.LayoutParams (150, 100) Public override View GetView (int position, View convertView, ViewGroup parent) create a new ImageView for each item referenced by the Adapter Public override long GetItemId (int position) Gallery.ItemClick += delegate (object sender, args) Gallery.Adapter = new ImageAdapter (this) Gallery gallery = (Gallery) FindViewById(Resource.Id.gallery) Set our view from the "main" layout resource ![]() Protected override void OnCreate (Bundle bundle) 打开Resources/Layout/main.axml并插入以下内容:Open Resources/Layout/Main.axml and insert the MainActivity.cs 并插入以下代码OnCreate()Open MainActivity.cs and insert the following code for the OnCreate() 在 "属性" 窗口中,将 "生成操作" 设置为 " AndroidResource"。In the Properties window, set the Build Action for each to AndroidResource. 将图像文件添加到项目的资源/可绘制目录。Add the image files to the project's Resources/Drawable directory. 查找要使用的一些照片,或下载这些示例图像。Find some photos you'd like to use, or download these sample images. 启动名为HelloGallery的新项目。Start a new project named HelloGallery. See ImageView.ScaleType for other image scaling options. 维度,最后将背景设置为使用构造函数中获取的 styleable 属性。dimensions, and then finally setting the background to use the styleable attribute acquired in the constructor. 图像的高度和宽度,将刻度设置为适合ImageViewheight and width for the image, setting the scale to fit the ImageView 通过从可绘制资源的本地数组应用映像来准备,并设置Gallery.LayoutParamsis prepared by applying an image from the local array of drawable resources, setting the Gallery.LayoutParams 在此方法中,成员ContextIn this method, the member Context 方法执行工作以将映像应用到ImageViewThe method does the work to apply an image to an ImageView 应返回项的行 id,但此处不需要。should return the row id of the item, but it's not needed here. 应返回适配器中指定位置的实际对象,但对于此示例,它将被忽略。should return the actual object at the specified position in the adapter, but it's ignored for this example. 接下来,这将实现从BaseAdapter继承的一些必需方法。Next, this implements some required methods inherited from BaseAdapter. 为 ImageAdapter 实例定义并保存到本地字段。for an ImageAdapter instance is defined and saved to a local field. 接下来是类构造函数,其中ContextNext is the class constructor, where the Context 首先,有几个成员变量,其中包括引用可绘制资源目录中保存的图像的 Id 的数组(资源/可绘制)。First, there are a few member variables, including an array of IDs that reference the images saved in the drawable resources directory (Resources/drawable). ![]() 这会显示 theselected 项的索引位置(从零开始)(在实际情况下,该位置可用于获取其他某个任务的完整大小的图像)。that displays the index position (zero-based) of theselected item (in a real world scenario, the position could be used to get the full sized image for some other task). 若要在单击库中的某一项时执行操作,请将匿名委托订阅ItemClickTo do something when an item in the gallery is clicked, an anonymous delegate is subscribed to the ItemClick ImageAdapter 是在下一步中创建的。The ImageAdapter is created in the next step. ![]() 然后,使用属性将自定义适配器(ImageAdapter)设置为要在 dallery 中显示的所有项的源。property is then used to set a custom adapter ( ImageAdapter) as the source for all items to be displayed in the dallery. 为内容视图设置 Main.axml 布局后,将从具有FindViewById的布局中捕获 Gallery。After the Main.axml layout is set for the content view, the Gallery is captured from the layout with FindViewById. 在本教程中,你将创建一个照片库,并在每次选择库项时显示 toast 消息。In this tutorial, you'll create a gallery of photos and then display a toast message each time a gallery item is selected. Gallery是一种布局小组件,用于显示水平滚动列表中的项,并将当前所选内容置于视图的中心。Gallery is a layout widget used to display items in a horizontally scrolling list and positions the current selection at the center of the view.Īndroid 4.1 (API 级别16)已弃用此小组件。This widget was deprecated in Android 4.1 (API level 16). Xamarin Android 库控件Xamarin.Android Gallery control ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |