gpt4 book ai didi

android - ScrollView 内的 map Recyclerview 在滚动时显示黑色闪烁背景

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:01:38 24 4
gpt4 key购买 nike

我在 recyclerview 行中使用了 map View 。我附上了截图。滚动 map 时显示黑色闪烁背景。

check my screenshot

适配器代码:

 @Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == TASK_VIEW) {
return new TasksViewHolder(LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_task_row, parent, false));
} else if (viewType == CHECKIN_VIEW) {
return new CheckInViewHolder(LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_checkin_row, parent, false));
} else {
return null;
}
}


@Override
private void onBindCheckInViewHolder(CheckInViewHolder holder, int position) {
final JobCheckIn singleCheckIn = (JobCheckIn) items.get(position);
holder.location.setText(singleCheckIn.getAddress());

holder.lastUpdated.setText(String.valueOf("Created " +
activity.getDateTime(singleCheckIn.getCreatedDateTime())));

holder.deleteTask.setOnClickListener(view -> jobInterface.deleteCheckIn(singleCheckIn.getId()));

float f = 0.0f;
if (holder.mapView != null && Float.compare(singleCheckIn.getLatitude(), f) != 0 &&
Float.compare(singleCheckIn.getLongitude(), f) != 0) {
holder.mapView.setVisibility(View.VISIBLE);
holder.initializeMapView();
if (holder.gMap != null) {
// The map is already ready to be used
moveMap(holder.gMap, singleCheckIn.getLatitude(), singleCheckIn.getLongitude());
}
}

}
public class CheckInViewHolder extends RecyclerView.ViewHolder implements OnMapReadyCallback {

MapView mapView;

GoogleMap gMap;


public CheckInViewHolder(View view) {
super(view);
mapView = view.findViewById(R.id.checkInMapView);

}


@Override
public void onMapReady(GoogleMap googleMap) {
MapsInitializer.initialize(context);
gMap = googleMap;
googleMap.getUiSettings().setMapToolbarEnabled(false);
if(items.get(getLayoutPosition())!=null )
moveMap(gMap,((JobCheckIn) items.get(getLayoutPosition())).getLatitude(), ((JobCheckIn) items.get(getLayoutPosition())).getLongitude());
}
public void initializeMapView() {
if (mapView != null) {
// Initialise the MapView
mapView.onCreate(null);
// Set the map ready callback to receive the GoogleMap object
mapView.getMapAsync(this);

}
}
}
public void moveMap(GoogleMap gMap, double latitude, double longitude) {
Log.v(TAG, "mapMoved: " + gMap);
LatLng latlng = new LatLng(latitude, longitude);
CameraUpdate cu = CameraUpdateFactory.newLatLngZoom(latlng, 6);
gMap.addMarker(new MarkerOptions().position(latlng));
gMap.moveCamera(cu);
}

I refer this link: Link but in this demo they used array adapter in my code we have used recyclerview adapter.

xml代码:

 <LinearLayout
android:layout_width="match_parent"
android:layout_height="150dp">

<com.google.android.gms.maps.MapView
android:id="@+id/checkInMapView"
android:layout_width="0dp"
android:layout_height="150dp"
android:layout_weight="1"
android:enabled="true"
android:visibility="gone"
map:cameraZoom="15"
map:liteMode="true"
map:mapType="normal" />

<!-- I have also tried adding transparent view as below but still no solution.

<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"/>-->

</LinearLayout>

I am not performing any zoom-In, Zoom-out or drag. Thanks in advance.

Google Issue Track


Update

以前我是在 viewHolder 中初始化 map ,而不是像上面提到的那样。

 onBindCheckInViewHolder(...){
holder.mapView.onCreate(null);
holder.mapView.getMapAsync(googleMap -> {
MapsInitializer.initialize(context);
gMap = googleMap;
googleMap.getUiSettings().setMapToolbarEnabled(false);
moveMap(gMap, singleCheckIn.getLatitude(), singleCheckIn.getLongitude());
});
}

最佳答案

在 AndroidManifest.xml 中写入这一行:

android:hardwareAccelerated="true"
 <application
android:name="com.xyz"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="@style/AppTheme">
</application>

有效。

关于android - ScrollView 内的 map Recyclerview 在滚动时显示黑色闪烁背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47646974/

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