当前位置: 编程技术>移动开发
本页文章导读:
▪软键盘挡住控件的有关问题 软键盘挡住控件的问题
在manifest的activity节点使用
<activity android:windowSoftInputMode="adjustResize" . . . >
当点击EditText控件弹出软键盘的时候,系统会自动调整控件的位置。代码http://github.com/s.........
▪ 用GPS获取自各儿的位置 用GPS获取自己的位置
最近做GPS一块,所以整理一点资料,希望对大家有用!
private Button button;
private TextView mTextview;
LocationManager lm;
double x, y;
/** Called when the activity is first created. */
@Overr.........
▪ 用GPS获取自各儿的位置并解析自己的确定位置 用GPS获取自己的位置并解析自己的确定位置
具体方法如下:
public void getLocation() throws IOException {
TextView tv = (TextView)this.findViewById(R.id.mytextView);
StringBuffer sb = new StringBuffer();
.........
[1]软键盘挡住控件的有关问题
来源: 互联网 发布时间: 2014-02-18
软键盘挡住控件的问题
在manifest的activity节点使用
当点击EditText控件弹出软键盘的时候,系统会自动调整控件的位置。
代码
http://github.com/shaobin0604/miscandroidapps/tree/master/WindowSoftInputMode/
参考
在manifest的activity节点使用
<activity android:windowSoftInputMode="adjustResize" . . . >
当点击EditText控件弹出软键盘的时候,系统会自动调整控件的位置。
代码
http://github.com/shaobin0604/miscandroidapps/tree/master/WindowSoftInputMode/
参考
- http://androidappdocs-staging.appspot.com/guide/topics/manifest/activity-element.html#wsoft
- http://www.chengyunfeng.com/2010/07/how-to-show-soft-keyboard
[2] 用GPS获取自各儿的位置
来源: 互联网 发布时间: 2014-02-18
用GPS获取自己的位置
最近做GPS一块,所以整理一点资料,希望对大家有用!
private Button button; private TextView mTextview; LocationManager lm; double x, y; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); getAddress(); button=(Button) findViewById(R.id.mTextview); button.setOnClickListener(new OnClickListener() { public void onClick(View v) { if(lm.isProviderEnabled(LocationManager.GPS_PROVIDER)!= true) { Intent callGPSSettingIntent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(callGPSSettingIntent); } } }); } public void getAddress() { mTextview = (TextView) this.findViewById(R.id.mTextview); //LocationManager lm; Location loc; lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); boolean isTrue = lm.isProviderEnabled("gps"); System.out.println("isTrue------------------->" + isTrue); // 获取location信息 loc = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); System.out.println("loc------------------> " + loc); if (loc != null) { x = loc.getLatitude(); // 获取纬度 y = loc.getLongitude(); // 获取经度 // int i = (int) (loc.getLatitude() * 1E6); // int j = (int) (loc.getLongitude() * 1E6); } lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, new LocationListener() { public void onLocationChanged(Location location) { // TODO Auto-generated method stub mTextview.setText("纬度======" + location.getLatitude() + "\n" + "经度=====" + location.getLongitude()); } public void onProviderDisabled(String provider) { // TODO Auto-generated method stub mTextview.setText("纬度======" + provider + "\n" + "经度=====" + provider); System.out .println("___________onProviderDisabled__________"); } public void onProviderEnabled(String provider) { // TODO Auto-generated method stub mTextview.setText("纬度======" + provider + "\n" + "经度=====" + provider); System.out .println("___________onProviderEnabled__________"); } public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub mTextview.setText("纬度======" + provider + "\n" + "经度=====" + provider); System.out .println("___________onStatusChanged__________"); } }); } }
当然也要打开服务GetLocation中打开
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.READ_PHONE_STATE" />
[3] 用GPS获取自各儿的位置并解析自己的确定位置
来源: 互联网 发布时间: 2014-02-18
用GPS获取自己的位置并解析自己的确定位置
具体方法如下:
public void getLocation() throws IOException { TextView tv = (TextView)this.findViewById(R.id.mytextView); StringBuffer sb = new StringBuffer(); Location loc; LocationManager locMan; LocationProvider locPro; List<LocationProvider> proList; locMan = (LocationManager)this.getSystemService(LOCATION_SERVICE); List<String> providers = locMan.getProviders(true); for(String provider : providers) { Log.i(TAG, provider); System.out.println("--------------------------------"+provider); locMan.requestLocationUpdates(provider, 1000, 0, new LocationListener(){ public void onLocationChanged( Location location) { // TODO Auto-generated method stub } public void onProviderDisabled( String provider) { // TODO Auto-generated method stub } public void onProviderEnabled( String provider) { // TODO Auto-generated method stub } public void onStatusChanged( String provider, int status, Bundle extras) { // TODO Auto-generated method stub }}); Location location = locMan.getLastKnownLocation(provider); //Location location = locMan.getLastKnownLocation(LocationManager.GPS_PROVIDER); //Location location = locMan.getProvider(LocationManager.GPS_PROVIDER); if(location!=null) { sb.append("lat:").append(location.getLatitude()).append(",").append(location.getLongitude()); Geocoder gc = new Geocoder(this, Locale.getDefault()); List<Address> addresses = gc.getFromLocation(location.getLatitude(), location.getLongitude(), 10); if(addresses.size() > 0) { Address address = addresses.get(0); for(int i = 0; i < address.getMaxAddressLineIndex(); i ++) { sb.append(address.getAddressLine(i)).append("\n"); sb.append(address.getLocality()).append("\n"); sb.append(address.getPostalCode()).append("\n"); sb.append(address.getCountryName()).append("\n"); } } } else { sb.append("No Location"); } tv.setText(sb); } }
权限为<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
最新技术文章: