首页 文章 精选 留言 我的

精选列表

搜索[组件化],共10000篇文章
优秀的个人博客,低调大师

android用户界面-组件Widget-地图视图MapView

一、在Google地图上显示本地的位置。 1、首先注意在AndroidManifest.xml文件中,增加权限: <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission> 在application中activity外,增加:uses-library <uses-library android:name="com.google.android.maps" /> 2、在类中,将extends Activity改为extends MapActivity 3、设置可放大缩小地图的控件。 在xml文件中,添加以下内容: <LinearLayout android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/zoom" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" > </LinearLayout> 在类中,加入: LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom); View zoomView = mapView.getZoomControls(); zoomLayout.addView(zoomView, new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); mapView.displayZoomControls(true); mapView.getController().setZoom(14);//设置缩放级别 p = this.getCurrentGeoPoint(); mapView.getController().animateTo(p);// 通过动画方式移动到指定坐标s 4、通过以下方法得到当前位置的经纬度 private GeoPoint getCurrentGeoPoint() { LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Location location = locationManager .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); return new GeoPoint((int) (location.getLatitude() * 1e6), (int) (location.getLongitude() * 1e6)); } 5、通过以下方式显示当前位置在地图上显示: class MapOverlay extends com.google.android.maps.Overlay { @Override public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { super.draw(canvas, mapView, shadow); //—translate the GeoPoint to screen pixels— Point screenPts = new Point(); mapView.getProjection().toPixels(p, screenPts); //—add the marker— Bitmap bmp = BitmapFactory.decodeResource( getResources(), R.drawable.pushpin); canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null); return true; } } 在oncreate方法中,加入: MapOverlay mapOverlay = new MapOverlay(); List<Overlay> listOfOverlays = mapView.getOverlays(); listOfOverlays.clear(); listOfOverlays.add(mapOverlay); 这样就能在屏幕中显示你当前位置的地图显示了; 如下图: 源代码见:http://henzil.googlecode.com/svn/trunk/android.googleMap01/ 二、输入地址,在地图上显示相应的位置。此方法是通过查询地址名称,返回一个list结果。在地图上显示: 此方法与上述方法基本一致,不同之处在于:是用getFromLocationName方法,来查询目的地的经纬度。 如下代码: // 通过系统默认区域设置进行地图定位 Geocoder gc = new Geocoder(this); mapView.setStreetView(true); try { // 通过地址名称描述返回一个查询结果的数组(后面参数为返回最大结果数) addresses = gc.getFromLocationName(address, 5); // 如果未查询到任何结果 if (addresses != null) { geoPoint = new GeoPoint( // 返回纬度,经度 (int) (addresses.get(0).getLatitude() * 1E6), (int) (addresses.get(0).getLongitude() * 1E6)); setTitle(addresses.get(0).getFeatureName()); MyOverlay myOverlay = new MyOverlay(); mapView.getOverlays().add(myOverlay); mapView.getController().setZoom(16); mapView.getController().animateTo(geoPoint); } } catch (Exception e) { e.printStackTrace(); } 如下图所示: 本文转自linzheng 51CTO博客,原文链接:http://blog.51cto.com/linzheng/1080684

优秀的个人博客,低调大师

android用户界面-组件Widget-画廊视图Gallery

Android的Gallery控件是个很不错的看图控件,大大减轻了开发者对于看图功能的开发,而且效果也比较美观。 /Chapter04_UI_Gallery01/src/com/amaker/test/MainActivity.java 代码 packagecom.amaker.test; importandroid.app.Activity; importandroid.content.Context; importandroid.os.Bundle; importandroid.view.View; importandroid.view.ViewGroup; importandroid.widget.BaseAdapter; importandroid.widget.Gallery; importandroid.widget.ImageView; publicclassMainActivityextendsActivity{ /**Calledwhentheactivityisfirstcreated.*/ @Override //创建时被调用 publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main); Galleryg=(Gallery)findViewById(R.id.Gallery01); g.setAdapter(newMyAdapter(this)); } classMyAdapterextendsBaseAdapter{ Contextcontext; MyAdapter(Contextcontext){ this.context=context; } privateInteger[]imgs={ R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8, R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8 }; publicintgetCount(){ returnimgs.length; } publicObjectgetItem(intitem){ returnitem; } publiclonggetItemId(intid){ returnid; } publicViewgetView(intposition,ViewconvertView,ViewGroupparent){ ImageViewimageView=newImageView(context); imageView.setImageResource(imgs[position]); imageView.setScaleType(ImageView.ScaleType.FIT_XY); imageView.setLayoutParams(newGallery.LayoutParams(136,88)); returnimageView; } } } /Chapter04_UI_Gallery01/res/layout/main.xml 代码 <?xmlversion="1.0"encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Gallery android:id="@+id/Gallery01" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Gallery> </LinearLayout> 本文转自linzheng 51CTO博客,原文链接:http://blog.51cto.com/linzheng/1080689

优秀的个人博客,低调大师

android用户界面-组件Widget-网格视图GridView

GridView按照行列的方式来显示内容。一般适合显示图标。图片等内容,主要用于设置Adapter。 通过基础类BaseAdapter类,重写getView()方法来设置图片显示格式。 /Chapter04_UI_GridView01/src/com/amaker/test/MainActivity.java 代码 packagecom.amaker.test; importandroid.app.Activity; importandroid.content.Context; importandroid.os.Bundle; importandroid.view.View; importandroid.view.ViewGroup; importandroid.widget.BaseAdapter; importandroid.widget.GridView; importandroid.widget.ImageView; publicclassMainActivityextendsActivity{ privateGridViewgv; @Override publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main); gv=(GridView)findViewById(R.id.GridView01); gv.setNumColumns(4); //gv.setNumColumns(3); //String[]strs={"a","a1","a2","b","b1","b2","c","c1","c2"}; //ArrayAdapter<String>adapter=newArrayAdapter<String>(this,android.R.layout.simple_gallery_item,strs); gv.setAdapter(newMyAdapter(this)); } classMyAdapterextendsBaseAdapter{ privateInteger[]imgs={ R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8, R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8 }; Contextcontext; MyAdapter(Contextcontext){ this.context=context; } publicintgetCount(){ returnimgs.length; } publicObjectgetItem(intitem){ returnitem; } publiclonggetItemId(intid){ returnid; } publicViewgetView(intposition,ViewconvertView,ViewGroupparent){ ImageViewimageView; if(convertView==null){ imageView=newImageView(context); imageView.setLayoutParams(newGridView.LayoutParams(45,45)); imageView.setAdjustViewBounds(false); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); imageView.setPadding(8,8,8,8); }else{ imageView=(ImageView)convertView; } imageView.setImageResource(imgs[position]); returnimageView; } } } 本文转自linzheng 51CTO博客,原文链接:http://blog.51cto.com/linzheng/1080690

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册