Piszę aplikację na Androida, gdzie tłem jest mapa i chcę umieścić na tym tle przyciski typu „Szukaj”, „Zaloguj się”. Utworzyłem xml jak poniżej:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<Button
android:id="@+id/buttonLogReg"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_gravity="top"
android:layout_weight="10"
android:baselineAligned="false"
android:text="@string/log_amp_reg"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<org.osmdroid.views.MapView
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:ignore="MissingConstraints" >
</org.osmdroid.views.MapView>
<org.osmdroid.views.MapView
android:id="@+id/mapview"
tilesource="Mapnik"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
A także kod Java, taki jak:
public class MainActivity extends Activity {
MapView map = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Context ctx = getApplicationContext();
Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));
setContentView(R.layout.activity_main);
map = (MapView)findViewById(R.id.map);
map.setTileSource(TileSourceFactory.MAPNIK);
map.setBuiltInZoomControls(true);
map.setMultiTouchControls(true);
IMapController mapController = map.getController();
mapController.setZoom(12.5);
GeoPoint startPoint = new GeoPoint(49.20, 19.94);
mapController.setCenter(startPoint);
Button logreg = findViewById(R.id.buttonLogReg);
logreg.setOnClickListener(onClickListener);
}
public void onResume(){
super.onResume();
map.onResume();
}
public void onPause(){
super.onPause();
map.onPause();
}
private View.OnClickListener onClickListener = new View.OnClickListener(){
@Override
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(), LoginRegister.class);
startActivity(intent);
}
};
}
Moje pytanie brzmi: dlaczego nie widzę przycisku na ekranie Androida, widzę tylko ruchomą mapę? Czy ktoś mógłby mi pomóc w tej sprawie?
1 odpowiedź
W rozmiarach map są dwie mapy problemów. Możesz je edytować .......
Xmlns: android = "http://schemas.android.com/apk/res/android" xmlns: app = "http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
tools:context=".MainActivity">
<Button
android:id="@+id/buttonLogReg"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_gravity="top"
android:layout_weight="10"
android:text="@string/log_amp_reg" />
<org.osmdroid.views.MapView
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="100dp"
tools:ignore="MissingConstraints" >
</org.osmdroid.views.MapView>
Podobne pytania
Nowe pytania
java
Java to język programowania wysokiego poziomu. Użyj tego tagu, jeśli masz problemy z używaniem lub zrozumieniem samego języka. Ten tag jest rzadko używany samodzielnie i jest najczęściej używany w połączeniu z [spring], [spring-boot], [jakarta-ee], [android], [javafx], [hadoop], [gradle] i [maven].