Java 移动地图时如何禁用滚动回收视图?
我创建了一个包含多个项目的recyclerView,但问题是当我想在地图中查找地址时 当我在地图上滚动时,回收器视图会移动,地图会失去滚动性 //回收器视图适配器类Java 移动地图时如何禁用滚动回收视图?,java,android,android-recyclerview,vertical-scrolling,neshan-map,Java,Android,Android Recyclerview,Vertical Scrolling,Neshan Map,我创建了一个包含多个项目的recyclerView,但问题是当我想在地图中查找地址时 当我在地图上滚动时,回收器视图会移动,地图会失去滚动性 //回收器视图适配器类 public class AddressAdapter extends RecyclerView.Adapter<AddressAdapter.Holder> { private List<FakeAddressList> objectList; public AddressAdapte
public class AddressAdapter extends RecyclerView.Adapter<AddressAdapter.Holder> {
private List<FakeAddressList> objectList;
public AddressAdapter(List<FakeAddressList> list) {
this.objectList = list;
}
@NonNull
@Override
public Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_address, parent, false);
return new Holder(view);
}
@Override
public void onBindViewHolder(@NonNull Holder holder, int position) {
holder.bindAddressList(objectList.get(position));
holder.imgClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
objectList.remove(position);
notifyDataSetChanged();
}
});
holder.imgEditLocation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AddAddressFragment addressFragment = new AddAddressFragment();
FragmentTransaction ft = fm.beginTransaction();
Bundle bundle = new Bundle();
bundle.putString("Title", objectList.get(position).getTitle());
bundle.putString("Address", objectList.get(position).getAddress());
bundle.putString("Phone", objectList.get(position).getPhoneNumber());
addressFragment.setArguments(bundle);
ft.replace(R.id.content_view, addressFragment).addToBackStack(null).commit();
}
});
holder.FooterLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AddDataFragment addDataFragment = new AddDataFragment();
FragmentTransaction ft = fm.beginTransaction();
Bundle bundle = new Bundle();
bundle.putString("Title", objectList.get(position).getAddress());
bundle.putString("Address", objectList.get(position).getAddress());
bundle.putString("Phone", objectList.get(position).getPhoneNumber());
addDataFragment.setArguments(bundle);
ft.replace(R.id.content_view, addDataFragment).addToBackStack(null).commit();
}
});
}
@Override
public int getItemCount() {
return objectList.size();
}
public class Holder extends RecyclerView.ViewHolder {
public TextView txtTitle;
public TextView txtSelect;
public TextView txtAddress;
public TextView txtPhone;
public ImageView imgClose;
public ImageView imgEditLocation;
public ConstraintLayout FooterLayout;
public MapView map;
public Holder(@NonNull View itemView) {
super(itemView);
txtTitle = itemView.findViewById(R.id.txtTitle);
txtAddress = itemView.findViewById(R.id.txtAddress);
txtPhone = itemView.findViewById(R.id.txtPhoneNumber);
txtSelect = itemView.findViewById(R.id.txtSelect);
imgClose = itemView.findViewById(R.id.imgClose);
imgEditLocation = itemView.findViewById(R.id.imgEditLocation);
FooterLayout = itemView.findViewById(R.id.FooterLayout);
map = itemView.findViewById(R.id.mapView);
txtTitle.setTypeface(Font_shabnam);
txtAddress.setTypeface(Font_shabnam);
txtPhone.setTypeface(Font_shabnam);
txtSelect.setTypeface(Font_shabnam);
}
public void bindAddressList(final FakeAddressList fakeAddressList) {
txtTitle.setText(fakeAddressList.getTitle());
txtAddress.setText(fakeAddressList.getAddress());
txtPhone.setText(fakeAddressList.getPhoneNumber());
if (fakeAddressList.getLng() != null) {
double lng = Double.valueOf(fakeAddressList.getLng());
double lat = Double.valueOf(fakeAddressList.getLat());
addUserMarker(new LngLat(lng, lat));
map.setFocalPointPosition(
new LngLat(Double.valueOf(fakeAddressList.getLng()), Double.valueOf(fakeAddressList.getLat())), 0.25f);
} else {
LngLat focalPoint;
focalPoint = new LngLat(51.33800, 35.69997);
map.setFocalPointPosition(focalPoint, 0f);
}
map.setZoom(15, 0.25f);
map.getLayers().add(NeshanServices.createBaseMap(NeshanMapStyle.STANDARD_DAY));
}
// This method gets a LngLat as input and adds a marker on that position
private void addUserMarker(LngLat loc) {
Marker marker;
VectorElementLayer userMarkerLayer;
userMarkerLayer = NeshanServices.createVectorElementLayer();
map.getLayers().add(userMarkerLayer);
// Creating marker style. We should use an object of type MarkerStyleCreator, set all features on it
// and then call buildStyle method on it. This method returns an object of type MarkerStyle
MarkerStyleCreator markStCr = new MarkerStyleCreator();
markStCr.setSize(20f);
// markStCr.setBitmap(BitmapUtils.createBitmapFromAndroidBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.ic_marker)));
markStCr.setBitmap(BitmapUtils.createBitmapFromAndroidBitmap(BitmapFactory.decodeResource(itemView.getResources(), R.drawable.ic_cherry)));
MarkerStyle markSt = markStCr.buildStyle();
// Creating user marker
marker = new Marker(loc, markSt);
// Clearing userMarkerLayer
// userMarkerLayer.clear();
// Adding user marker to userMarkerLayer, or showing marker on map!
userMarkerLayer.add(marker);
}
}
}
公共类AddressAdapter扩展了RecyclerView.Adapter{
私有列表对象列表;
公共地址适配器(列表){
this.objectList=list;
}
@非空
@凌驾
public Holder onCreateViewHolder(@NonNull ViewGroup父级,int viewType){
View View=LayoutInflater.from(parent.getContext()).flate(R.layout.recycler_address,parent,false);
返回新的持有者(视图);
}
@凌驾
public void onBindViewHolder(@NonNull Holder,int位置){
holder.bindAddressList(objectList.get(position));
holder.imgClose.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
objectList.remove(位置);
notifyDataSetChanged();
}
});
holder.imgEditLocation.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
AddAddressFragment addressFragment=新的AddAddressFragment();
FragmentTransaction ft=fm.beginTransaction();
Bundle=新Bundle();
bundle.putString(“Title”,objectList.get(position.getTitle());
bundle.putString(“地址”,objectList.get(position.getAddress());
bundle.putString(“Phone”,objectList.get(position.getPhoneNumber());
addressFragment.setArguments(bundle);
ft.replace(R.id.content_视图,addressFragment).addToBackStack(null.commit();
}
});
holder.FooterLayout.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
AddDataFragment AddDataFragment=新的AddDataFragment();
FragmentTransaction ft=fm.beginTransaction();
Bundle=新Bundle();
bundle.putString(“Title”,objectList.get(position.getAddress());
bundle.putString(“地址”,objectList.get(position.getAddress());
bundle.putString(“Phone”,objectList.get(position.getPhoneNumber());
addDataFragment.setArguments(bundle);
ft.replace(R.id.content_视图,addDataFragment).addToBackStack(null.commit();
}
});
}
@凌驾
public int getItemCount(){
返回objectList.size();
}
公共类持有者扩展了RecyclerView.ViewHolder{
公共文本视图txtTitle;
公共文本视图txtSelect;
公共文本视图txtAddress;
公共文本视图txtPhone;
公共图像查看imgClose;
公共图像视图imgEditLocation;
公共约束页脚布局;
公共地图视图;
公共持有者(@NonNull View itemView){
超级(项目视图);
txtTitle=itemView.findViewById(R.id.txtTitle);
txtAddress=itemView.findViewById(R.id.txtAddress);
txtPhone=itemView.findViewById(R.id.txtPhoneNumber);
txtSelect=itemView.findviewbyd(R.id.txtSelect);
imgClose=itemView.findviewbyd(R.id.imgClose);
imgEditLocation=itemView.findviewbyd(R.id.imgEditLocation);
FooterLayout=itemView.findViewById(R.id.FooterLayout);
map=itemView.findviewbyd(R.id.mapView);
txtTitle.setTypeface(Font_-shabnam);
txtAddress.setTypeface(字体);
txtPhone.setTypeface(字体);
txtSelect.setTypeface(Font_-shabnam);
}
公共无效bindAddressList(最终伪造地址列表伪造地址列表){
setText(fakeAddressList.getTitle());
setText(fakeAddressList.getAddress());
setText(fakeAddressList.getPhoneNumber());
if(fakeAddressList.getLng()!=null){
double lng=double.valueOf(fakeAddressList.getLng());
double-lat=double.valueOf(fakeAddressList.getLat());
addUserMarker(新LngLat(液化天然气,拉丁美洲));
map.setFocalPointPosition(
新LngLat(Double.valueOf(fakeAddressList.getLng()),Double.valueOf(fakeAddressList.getLat()),0.25f);
}否则{
LngLat焦点;
焦点=新LngLat(51.33800,35.69997);
映射设置焦点位置(焦点,0f);
}
地图设置缩放(15,0.25f);
map.getLayers().add(NeshanServices.createBaseMap(NeshanMapStyle.STANDARD_DAY));
}
//此方法获取一个LngLat作为输入,并在该位置添加一个标记
专用void addUserMarker(LngLat loc){
标记;
VectoreElementLayer用户标记层;
userMarkerLayer=NeshanServices.CreateVectoreElementLayer();
map.getLayers().add(userMarkerLayer);
//创建标记样式。我们应该使用类型为MarkerStyleCreator的对象,在其上设置所有功能
//然后对其调用buildStyle方法。此方法返回MarkerStyle类型的对象
MarkerStyleCreator markStCr=新的MarkerStyleCreator();
标记设置大小(20f);
//markStCr.setBitmap(BitmapUtils.createbitmapfromandoidbitmap(BitmapFactory.decodeResource(getResources(),R.drawable.ic_marker));
markStCr.setBitmap(BitmapUtils.createbitmapfromandoidbitmap(BitmapFactory.decodeResource(itemView.getResources(),R.drawable.ic)));
MarkerStyle markSt=markStCr.buildStyle();
//创建用户标记
标记=新标记(loc、markSt);
//清楚的
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/HeaderLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:background="@drawable/_orange_shape_b_r_l"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0">
<ImageView
android:id="@+id/imgClose"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:src="@drawable/ic_close"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/imgEditLocation"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:src="@drawable/ic_edit_location"
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" />
<TextView
android:id="@+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="تهرانپارس"
android:textSize="18dp"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="@+id/imgEditLocation"
app:layout_constraintEnd_toStartOf="@+id/imgEditLocation"
app:layout_constraintStart_toEndOf="@+id/imgClose"
app:layout_constraintTop_toTopOf="@+id/imgClose" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/MiddleLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/HeaderLayout"
app:layout_constraintVertical_bias="0.0">
<org.neshan.ui.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="300dp"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/imgAddress"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:src="@drawable/ic_address"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/mapView"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="@+id/txtAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="خیابان فلانی کوچه 1"
android:textSize="18dp"
app:layout_constraintBottom_toBottomOf="@+id/imgAddress"
app:layout_constraintTop_toTopOf="@+id/imgAddress" />
<ImageView
android:id="@+id/imgPhone"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:src="@drawable/ic_phone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/imgAddress"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="@+id/txtPhoneNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="0916123456"
android:textSize="18dp"
app:layout_constraintBottom_toBottomOf="@+id/imgPhone"
app:layout_constraintTop_toTopOf="@+id/imgPhone" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/FooterLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:background="@drawable/_black_shape_t_r_l"
android:padding="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/MiddleLayout"
app:layout_constraintVertical_bias="0.0">
<TextView
android:id="@+id/txtSelect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="انتخاب"
android:textColor="@color/white"
android:textSize="18dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
public class RegisterAddressFragment extends Fragment
implements View.OnClickListener {
private RecyclerView recycler_SelectAddress;
private Button btnNewAddress;
private ProgressBar progressBar;
private ConstraintLayout MainLayout;
private Bundle bundle;
private ArrayList<FakeAddressList> list = new ArrayList<>();
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
this.bundle = getArguments();
if (bundle != null) {
list.add(new FakeAddressList(bundle.getString("Title"),
bundle.getString("Address"),
bundle.getString("Phone"),
bundle.getString("Lng"),
bundle.getString("Lat")));
}
}
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_register_address, container, false);
init(v);
initRecyclerView();
return v;
}
private void init(View v) {
recycler_SelectAddress = v.findViewById(R.id.recycler_SelectAddress);
btnNewAddress = v.findViewById(R.id.btnNewAddress);
btnNewAddress.setOnClickListener(this);
progressBar = v.findViewById(R.id.progressbar);
MainLayout = v.findViewById(R.id.MainLayout);
Thread thread = new Thread() {
@Override
public void run() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
// Do some stuff
progressBar.setVisibility(View.GONE);
MainLayout.setVisibility(View.VISIBLE);
}
});
}
};
thread.start(); //start the thread
}
private void initRecyclerView() {
list.add(new FakeAddressList("اصفهان", "شاهین شهر خیابان نوشین پلاک 1", "987654321"));
list.add(new FakeAddressList("اهواز", "کیانپارس کوچه بنی هاشم پلاک 33", "123456789"));
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
layoutManager.setOrientation(RecyclerView.VERTICAL);
AddressAdapter addressAdapter = new AddressAdapter(list);
recycler_SelectAddress.setLayoutManager(layoutManager);
recycler_SelectAddress.setAdapter(addressAdapter);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.btnNewAddress:
AddAddressFragment addressFragment = new AddAddressFragment();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.content_view, addressFragment).addToBackStack(null).commit();
break;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="@color/tusi"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ProgressBar
android:id="@+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateTint="@color/red2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/MainLayout"
tools:visibility="visible"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_SelectAddress"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="32dp"
app:layout_constraintBottom_toTopOf="@+id/btnNewAddress"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/btnNewAddress"
android:layout_width="match_parent"
android:layout_height="0dp"
android:backgroundTint="@color/navy_blue"
android:insetLeft="0dp"
android:insetTop="0dp"
android:insetRight="0dp"
android:insetBottom="0dp"
android:text="آدرس جدید"
android:textSize="22sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
map.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
itemView.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});