我有一个片段,我想要谷歌地图和两个微调器来选择车号和一天。你知道为什么我的纺纱厂没有展示吗?当我查看他们显示的axml文件时,但是当我在手机上运行应用程序时,只显示地图。我错过了什么?
这可能是.axml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="1">
<TableRow>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/txtRefreshData"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Car number"
android:layout_marginLeft="40dp" />
<Spinner
android:id="@+id/spinnerCar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:margin_left="30dp"
android:layout_toRightOf="@id/txtRefreshData"
android:layout_marginLeft="10dp" />
<TextView
android:id="@+id/txtspinnerDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Day"
android:layout_toRightOf="@id/spinnerCar"
android:layout_marginLeft="30dp" />
<Spinner
android:id="@+id/spinnerDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/txtspinnerDate"
android:layout_marginLeft="10dp" />
</RelativeLayout>
</TableRow>
<TableRow>
<LinearLayout
android:id="@+id/map_placeholder"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</TableRow>
</TableLayout>
这是我的.cs
GoogleMap map;
MapFragment mapFragment;
List<LatLng> markers = new List<LatLng>();
List<string> carnumbers = new List<string>();
MarkerOptions markerOptions;
TextView txtRefreshData;
public void OnMapReady(GoogleMap googleMap)
{
int ct = 1;
if (markers.Count > 0)
{
foreach (var item in markers)
{
map = googleMap;
markerOptions = new MarkerOptions();
markerOptions.SetPosition(item);
markerOptions.SetTitle("My Position" + ct);
map.AddMarker(markerOptions);
ct++;
}
FitAllMarkers(map);
}
}
private void FitAllMarkers(GoogleMap googleMap)
{
LatLngBounds.Builder builder = new LatLngBounds.Builder();
foreach (LatLng item in markers)
{
builder.Include(item);
}
LatLngBounds bounds = builder.Build();
CameraUpdate cu = CameraUpdateFactory.NewLatLngBounds(bounds, 100);
googleMap.AnimateCamera(cu);
}
public override void OnActivityCreated(Bundle savedInstanceState)
{
base.OnActivityCreated(savedInstanceState);
mapFragment = MapFragment.NewInstance();
var ft = Activity.FragmentManager.BeginTransaction();
ft.Add(Resource.Id.map_placeholder, mapFragment).Commit();
mapFragment.GetMapAsync(this);
}
public async override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view = inflater.Inflate(Resource.Layout.LiveTrackingAdminFragment, container, false);
this.Activity.Title = "Live Tracking";
Spinner spinner = view.FindViewById<Spinner>(Resource.Id.spinnerCar);
Spinner spinner = view.FindViewById<Spinner>(Resource.Id.spinnerDay);
return view;
}
答案 0 :(得分:3)
I)在您的第一个TableRow中,使用固定大小设置RelativeLayout的高度,例如android:layout_height="50dp"
II)在spinnerCar
,删除android:margin_left
,它无效并可能导致错误
III)在每个微调器(spinnerCar
和spinnerDate
)中设置固定宽度,例如android:layout_width="120dp"