首页 文章 精选 留言 我的

精选列表

搜索[宁静视图],共8558篇文章
优秀的个人博客,低调大师

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

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

Android视图篇之一:Android常见基本布局

Android中,布局都是直接或间接的继承自ViewGroup类,其中,ViewGroup的直接子类目前有: AbsoluteLayout, AdapterView<T extends Adapter>, DrawerLayout, FragmentBreadCrumbs, FrameLayout, GridLayout, LinearLayout, PagerTitleStrip, RelativeLayout,SlidingDrawer, SlidingPaneLayout, ViewPager。 其中,DrawerLayout、PagerTitleStrip、SlidingPaneLayout和ViewPager是AndroidAPI level 4(1.6版本)及其以后通过引入android.support.v4得以支持。GridLayout是AndroidAPI level 7(2.1版本)通过引入android.support.v7得以支持。SlidingDrawer在AndroidAPI level 17(4.2版本)废弃。FragmentBreadCrumbs也较少用到。 同时,虽然TableLayout是继承自LinearLayout,但TableLayout在日常开发中也经常用到,TableLayout也算在其中。因此,本文将主要讲解Android中最常见的几种布局方式:FrameLayout、LinearLayout、RelativeLayout、TableLayout和AbsoluteLayout。AdapterView<T extends Adapter>将在下一篇中详细阐述。 1、FrameLayout Framelayout是Android中最简单的一种布局方式。其内部的view都是从屏幕左上角开始堆放,如果有多个view,后一个view的可见区域将遮挡前一个view相应区域。 可以简单的理解成墙角堆放积木的效果。 若想达到不遮挡前一view,可以通过对view设置layout_gravity进行简单定位。 layout_gravity含义:此view相对于其父布局的对其方式。 2、LinearLayout LinearLayout即线性布局,可以通过设定设定其android:orientation属性值来确定是水平方向上的线性布局还是垂直方向上的线性布局。默认为水平方向的线性布局方式。 LinearLayout中的view有一个非常重要的属性android:weight,表示在相应方向上剩余空间的比重,优先级高于view本身相应方向上的长度。以水平方向为例,如果设置了android:weight,则android:width属性值建议设置成0dp,以取得更好的性能效果。对于两个view而言,其中一个未设置android:weight属性,则默认值为0,另一个设置了android:weight属性值为1,由1/(1+0)=100%,其将占据此方向上全部的剩余空间。 同时,对于LinearLayout中的view,同样可以使用android:layout_gravity属性,但是,是有条件的。对于水平线性布局而言,android:layout_gravity在水平方向上失效;对于垂直线性布局而言,android:layout_gravity在垂直方向上失效。 3、RelativeLayout RelativeLayout是Android中相对最灵活的一种布局方式。主要可以设置与父控件的对齐方式和相对于其他控件的对其方式。通过灵活设置不同的对齐属性,可以达到复杂的布局效果,但前提是view需要具有相应的android:id="@+id/viewid"。 4.TableLayout TableLayout即表格布局。使用TableLayout时需要注意以下几点: 1). TbaleLayout类似于Html中的table,但是默认行列式没有边框的; 2).TableLayout是LinearLayout的子类,因为可以对其中的view使用android:weight属性; 3). Tablelayout的children不一定是TableRow,也可以直接是其他的view。行列也不像html中的table那样具有明显的对其模式; 4). TableLayout中的children无需指定宽度,宽度默认都是match_parent。为其指定其他宽度值都是无效的; 5). TableLayout中的children如果为TableRow,则无需为其指定高度,高度默认都是wrap_content。为其指定其他高度都是无效的,若children为其他view,则可以指定其他宽度值; 6).TableLayout的属性android:collapseColumns设置隐藏,但是只针对child为tablerow有效; 7).tablelayout的属性android:stretchColumns设置可拉伸列,android:shrinkColumns 设置可收缩列,优先级都是大于weight属性。 5、AbsoluteLayout AbsoluteLayout即绝对布局(坐标布局),是相对于父控件的左上角开始的布局方式。通过给AbsoluteLayout中的view设置android:layout_x和android:layout_y属性值来确定此view本身左上角的位置,以此完成定位。 AbsoluteLayout在AndroidAPI level 3(1.5版本)中已经被废弃,由于此种布局方式不能较好的适配Android多种不同的屏幕效果,不推荐使用。 --------------------------------------------------------------------------------- 笔者水平有限,若有错漏,欢迎指正,如果转载以及CV操作,请务必注明出处,谢谢! 分类: Android 本文转自Windstep博客园博客,原文链接:http://www.cnblogs.com/lwbqqyumidi/p/3405611.html,如需转载请自行联系原作者

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

Android开发 - 掌握ConstraintLayout(十)按比例设置视图大小

有时候在布局界面的时候,UI要求某个View或者某张图片按比例显示,以适应不同的屏幕分辨率。 通常我们时通过自定义View或者引入第三方的库来解决。现在我们既然已经使用了ConstraintLayout,它本身就支持这样的按比例设置View大小的功能。 下面我们来介绍如何使用: 首先我们在布局中添加一个View: 此时,没有添加任何约束,显示的比例就是原始图片的比例。 添加水平方向的约束: 添加完水平方向的约束后,注意此时默认的宽高为wrap_content。 将高度设置为match_constraint 如上图:这里我们将高度设置为match_constraint,然后发现下面出现了一个三角,这个就是设置View比例的地方。 设置View比例 下面我们点击这个三角形,并设置宽高的比例: 1:1 1:2 这里设置的是宽度:高度的比例,我们查看源码可以看到这个属性: 此时我们改变View的宽度,就会发现其高度也会保持这个比例而相应地变化了: 总结 本文我们是以宽度:高度进行View比例的设置,当然我们也可以以高度:宽度进行设置,道理都是一样的。 设置View的比例也是ConstraintLayout相对于传统的布局容器一个强大的功能,它使得布局更加灵活,更加容易得进行屏幕适配。 下一篇:Android开发 - 掌握ConstraintLayout(十一)复杂动画!如此简单!,我们将介绍使用ConstraintLayout创建复杂动画。 如有更多疑问,请参考我的其它Android相关博客:我的博客地址

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

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

Rocky Linux

Rocky Linux

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

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册