gpt4 book ai didi

java - 在 Android 中定位 map 上的按钮(在同一 Activity 上)时出现问题

转载 作者:行者123 更新时间:2023-12-01 20:17:37 25 4
gpt4 key购买 nike

我正在 Android 中编写一个应用程序,其中背景是 map ,我想在这个背景上放置一些按钮,例如“搜索”、“登录”。我创建了如下所示的 xml:

<?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>

还有 Java 代码,例如:

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);
}
};
}

所以我的问题是:为什么我在 Android 屏幕上看不到按钮,只能看到可移动 map ?有人可以帮我解决这个问题吗?

最佳答案

map 尺寸中有两个问题 map 。您可以编辑它们......

<?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="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>


</LinearLayout>

关于java - 在 Android 中定位 map 上的按钮(在同一 Activity 上)时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58950104/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com