我最近開始使用Android。我沒有那麼多Android的經驗。這是我第一次使用Android。我需要將屏幕分成兩半,然後執行幾項任務。將Android屏幕分成兩半等分
- 劃分屏幕在兩個相等的半,在第二半之後(意味着下半部)我需要一個名爲
Latitude
然後對應於該一個Textbox
標籤,將顯示當前的緯度值,並命名爲Longitude
另一個標籤和對應於另一個Textbox
並且將顯示當前的經度值。
我開始研究這個,並且我取得了一些進展 - 下面是我正在使用的XML文件將屏幕分成兩半。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.8"
android:background="#000000" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#000000" >
<!-- Latitude Label -->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Latitude"
android:textColor="#372c24" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dip"
android:layout_marginTop="5dip"
android:singleLine="true" />
<!-- Longitude Label -->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Longitude"
android:textColor="#372c24" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:password="true"
android:singleLine="true" />
</LinearLayout>
</LinearLayout>
我的問題是 -
- 使用上述XML文件後,我無法看到我的
both label
和both textbox
正確對Android屏幕,有什麼我很想念在我的XML文件?其次,我如何在相應的文本框中顯示當前的緯度和經度值。
任何幫助將不勝感激,因爲我是Android世界的新手。
更新: - 下面是我在油漆中做的圖,我想要這樣的東西。
如果你看看屏幕,它分爲兩部分,在下半部分有兩個標籤(經度和緯度),它應該是這樣的,每個標籤的前面,都會有是一個文本框,它將保存相應的緯度和經度值。
更新代碼: -對於當前的當前位置 -
public class MainActivity extends Activity implements LocationListener {
private TextView latituteField;
private TextView longitudeField;
private LocationManager locationManager;
private String provider;
private static final String TAG = "CurrentLocation";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
latituteField = (TextView) findViewById(R.id.lat1);
longitudeField = (TextView) findViewById(R.id.lat2);
// Get the location manager
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// Define the criteria how to select the location provider -> use
// default
Criteria criteria = new Criteria();
provider = locationManager.getBestProvider(criteria, false);
locationManager.requestLocationUpdates(provider, 0, 0, this);
Location location = locationManager.getLastKnownLocation(provider);
onLocationChanged(location);
}
@Override
protected void onDestroy() {
super.onDestroy();
locationManager.removeUpdates(this);
}
@Override
public void onLocationChanged(Location location) {
if (location != null) {
System.out.println("Provider " + provider + " has been selected.");
int lat = (int) (location.getLatitude());
int lng = (int) (location.getLongitude());
Log.v(TAG, lat+ " "+ lng);
latituteField.setText(String.valueOf(lat));
longitudeField.setText(String.valueOf(lng));
} else {
latituteField.setText("Provider not available");
longitudeField.setText("Provider not available");
}
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
但是,下面的代碼沒有顯示在對應的文本框中輸入任何經緯度值?我在做什麼錯?
哎呀..對不起,我忘了接受答案。我現在做了.. – AKIWEB 2012-08-02 04:34:56