Android 实现仿淘宝地址多级选择器

news2025/5/26 8:00:12

先看下效果图

 仿淘宝的选择完城市出来的选择省市区之类的,这个支持自定义层级,多少层都可以使用,接下来是代码:

BottomPopUtils.class,我写了一个工具类,方便全局调用
public class BottomPopUtils {

    public static ProjectTitleAdapter titleAdapter;
    public static ProjectAdapter adapter1;
    public static PopupWindow popupWindow;
    public static View contentView;
    public static StringBuilder result;

    public static void showPopWindow(List<ProjectTitleItemBean> listTop, List<ProjectItemBean> listContent, Activity context, Finish finish) {
        result = new StringBuilder();
        Map<Integer, List<ProjectItemBean>> nowMap = new HashMap<>();

        //加载弹出框的布局
        contentView = LayoutInflater.from(context).inflate(
                R.layout.popupwindow, null);
        // 设置按钮的点击事件
        ImageView ivFinish = contentView.findViewById(R.id.iv_finish);

        RecyclerView rl = contentView.findViewById(R.id.rl);
        RecyclerView rlTitle = contentView.findViewById(R.id.rl_title);

        //这个为了取出第一级的数据
        List<ProjectItemBean> item = new ArrayList<>();
        for (int i = 0; i < listContent.size(); i++) {
            if (listContent.get(i).getLevel() == 0) {
                item.add(listContent.get(i));
            }
        }
        List<ProjectItemBean> firstMap = new ArrayList<>();

        for (int i = 0; i < item.size(); i++) {
            ProjectItemBean itemBean1 = item.get(i);
            firstMap.add(BeanCloneUtil.cloneTo(itemBean1));
        }

        nowMap.put(0, firstMap);

        titleAdapter = new ProjectTitleAdapter(context, listTop, (itemBean, position) -> {
            //每次用户点击顶部集合的时候,移除掉点击下标后的所有数据
            int size = listTop.size();
            for (int i = position + 1; i < size; i++) {
                listTop.remove(position + 1);
            }

            titleAdapter.notifyDataSetChanged();


            Iterator<Map.Entry<Integer, List<ProjectItemBean>>> iterator = nowMap.entrySet().iterator();
            while (iterator.hasNext()) {
                Map.Entry<Integer, List<ProjectItemBean>> entry = iterator.next();
                Integer key = entry.getKey();
                if (key > position) {
                    iterator.remove();
                }
            }

            List<ProjectItemBean> items = new ArrayList<>();
            List<ProjectItemBean> listNow = nowMap.get(position);
            if (listNow != null) {
                for (int i = 0; i < listNow.size(); i++) {
                    if (listNow.get(i).getName().equals(itemBean.getName())) {
                        listNow.get(i).setChoose(true);
                    } else {
                        listNow.get(i).setChoose(false);
                    }
                    items.add(listNow.get(i));
                }
            }

            item.clear();
            item.addAll(items);
            adapter1.notifyDataSetChanged();

        });


        rlTitle.setLayoutManager(new LinearLayoutManager(context));
        rlTitle.setAdapter(titleAdapter);


        adapter1 = new ProjectAdapter(context, item, itemBean -> {
            List<ProjectItemBean> mapItem = new ArrayList<>();
            if (!nowMap.containsKey(itemBean.getLevel())) {
                for (int i = 0; i < item.size(); i++) {
                    ProjectItemBean itemBean1 = item.get(i);
                    mapItem.add(BeanCloneUtil.cloneTo(itemBean1));
                }
                nowMap.put(itemBean.getLevel(), mapItem);
            }

            for (int i = 0; i < item.size(); i++) {
                item.get(i).setChoose(false);
            }
            itemBean.setChoose(true);



            listTop.get(itemBean.getLevel()).setCode(itemBean.getCode());
            listTop.get(itemBean.getLevel()).setId(itemBean.getId());
            listTop.get(itemBean.getLevel()).setName(itemBean.getName());
            listTop.get(itemBean.getLevel()).setChoose(true);
            titleAdapter.notifyDataSetChanged();


            //如果当前选择的数据是否有子集合
            if (itemBean.getChildList() != null && itemBean.getChildList().size() > 0) {
                item.clear();
                if (itemBean.getChildList() == null) {
                    item.addAll(new ArrayList<>());
                } else {
                    item.addAll(itemBean.getChildList());
                }

                ProjectTitleItemBean bean = new ProjectTitleItemBean();
                bean.setName("请选择");
                bean.setChoose(false);
                listTop.add(bean);

                titleAdapter.notifyDataSetChanged();
                adapter1.notifyDataSetChanged();
            } else {
                adapter1.notifyDataSetChanged();
            }
        });
        rl.setLayoutManager(new LinearLayoutManager(context));
        rl.setAdapter(adapter1);

        ivFinish.setOnClickListener(v -> {
            if (popupWindow != null && popupWindow.isShowing()) {
                for (int i = 0; i < listTop.size(); i++) {
                    String name = listTop.get(i).getName();
                    if (i == listTop.size() - 1) {
                        result.append(name);
                    } else {
                        result.append(name + "--");
                    }
                    Log.i("已选中的值", name);
                }
                finish.finish(result.toString());
                popupWindow.dismiss();
                backgroundAlpha(1.0f, context);
            }
        });

        popupWindow = new PopupWindow(contentView,
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        popupWindow.setFocusable(false);// 取得焦点
        //注意  要是点击外部空白处弹框消息  那么必须给弹框设置一个背景色  不然是不起作用的
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        //点击外部消失
        popupWindow.setOutsideTouchable(false);
        //设置可以点击
        popupWindow.setTouchable(true);
        //进入退出的动画,指定刚才定义的style
        popupWindow.setAnimationStyle(R.style.ipopwindow_anim_style);
        openPopWindow();
        backgroundAlpha(0.4f, context);

    }

    /**
     * 按钮的监听
     */
    private static void openPopWindow() {
        //从底部显示
        popupWindow.showAtLocation(contentView, Gravity.BOTTOM, 0, 0);
    }

    private static void backgroundAlpha(float f, Activity context) {
        WindowManager.LayoutParams lp = context.getWindow().getAttributes();
        lp.alpha = f;
        context.getWindow().setAttributes(lp);
    }

    public interface Finish {
        void finish(String result);
    }
}
BeanCloneUtil 用来复制bean类,保证数据的修改不会影响其他map
public abstract class BeanCloneUtil {
    @SuppressWarnings("unchecked")
    public static <T> T cloneTo(T src) throws RuntimeException {
        ByteArrayOutputStream memoryBuffer = new ByteArrayOutputStream();
        ObjectOutputStream out = null;
        ObjectInputStream in = null;
        T dist = null;
        try {
            out = new ObjectOutputStream(memoryBuffer);
            out.writeObject(src);
            out.flush();
            in = new ObjectInputStream(new ByteArrayInputStream(memoryBuffer.toByteArray()));
            dist = (T) in.readObject();
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            if (out != null)
                try {
                    out.close();
                    out = null;
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            if (in != null)
                try {
                    in.close();
                    in = null;
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
        }
        return dist;
    }
}
ProjectTitleAdapter  顶部的列表适配器
public class ProjectTitleAdapter extends RecyclerView.Adapter<ProjectTitleAdapter.ViewHolder> {
    private Context context;
    private List<ProjectTitleItemBean> list;
    private ProjectTitleItemClick itemClick;

    public ProjectTitleAdapter(Context context, List<ProjectTitleItemBean> list,
                               ProjectTitleItemClick itemClick) {
        this.context = context;
        this.list = list;
        this.itemClick = itemClick;
    }

    public ProjectTitleAdapter(Context context, List<ProjectTitleItemBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.pop_time_line, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        ProjectTitleItemBean item = list.get(position);

        if (item.isChoose()) {
            holder.viewCircleNo.setVisibility(View.GONE);
            holder.viewCircleYes.setVisibility(View.VISIBLE);
        } else {
            holder.viewCircleNo.setVisibility(View.VISIBLE);
            holder.viewCircleYes.setVisibility(View.GONE);
        }

        holder.tvName.setText(item.getName());

        holder.tvName.setOnClickListener(view -> {
            if (item.isChoose()) {
                itemClick.itemListener(item, position);
            }
        });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private final TextView tvName;
        private final View viewCircleNo;
        private final View viewCircleYes;

        public ViewHolder(View itemView) {
            super(itemView);
            tvName = itemView.findViewById(R.id.tv_name);
            viewCircleNo = itemView.findViewById(R.id.view_circle_no);
            viewCircleYes = itemView.findViewById(R.id.view_circle_yes);
        }
    }
}
ProjectAdapter 底部的列表适配器
public class ProjectAdapter extends RecyclerView.Adapter<ProjectAdapter.ViewHolder> {
    private Context context;
    private List<ProjectItemBean> list;
    private ProjectItemClick itemClick;

    public ProjectAdapter(Context context, List<ProjectItemBean> list,
                          ProjectItemClick itemClick) {
        this.context = context;
        this.list = list;
        this.itemClick = itemClick;
    }

    public ProjectAdapter(Context context, List<ProjectItemBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.adapter_project, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        ProjectItemBean item = list.get(position);

        if (item.isChoose()) {
            holder.tvName.setTypeface(null, Typeface.BOLD);
            holder.ivSelect.setVisibility(View.VISIBLE);
        } else {
            holder.tvName.setTypeface(null, Typeface.NORMAL);
            holder.ivSelect.setVisibility(View.INVISIBLE);
        }

        holder.tvName.setText(item.getName());

        holder.tvName.setOnClickListener(view -> {
            itemClick.itemListener(item);
        });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private final TextView tvName;
        private final ImageView ivSelect;

        public ViewHolder(View itemView) {
            super(itemView);
            tvName = itemView.findViewById(R.id.tv_name);
            ivSelect = itemView.findViewById(R.id.iv_select);
        }
    }
}
ProjectTitleItemBean 顶部的实体类
public class ProjectTitleItemBean {
    private String name;
    private String id;
    private String code;
    private boolean isChoose;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public boolean isChoose() {
        return isChoose;
    }

    public void setChoose(boolean choose) {
        isChoose = choose;
    }
}
ProjectItemBean 底部实体类
public class ProjectItemBean implements Serializable {
    private String id;
    private String name;
    private String code;
    private boolean isChoose;
    private int level;
    private List<ProjectItemBean> childList = new ArrayList<>();
    private ProjectItemBean parent;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public boolean isChoose() {
        return isChoose;
    }

    public void setChoose(boolean choose) {
        isChoose = choose;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public List<ProjectItemBean> getChildList() {
        return childList;
    }

    public void setChildList(List<ProjectItemBean> childList) {
        this.childList = childList;
    }

    public ProjectItemBean getParent() {
        return parent;
    }

    public void setParent(ProjectItemBean parent) {
        this.parent = parent;
    }
}
ProjectTitleItemClick 顶部条目点击
public interface ProjectTitleItemClick {
    void itemListener(ProjectTitleItemBean itemBean,int position);
}
ProjectItemClick 底部条目点击
public interface ProjectItemClick {
    void itemListener(ProjectItemBean itemBean);
}
MainActivity 主页面的代码,顶部的集合默认给一条就行,后续的顶部集合自增或自减都是在适配器里完成的
public class MainActivity extends AppCompatActivity {

    private TextView tvContent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button bottom = findViewById(R.id.btn_bottom);
        tvContent = findViewById(R.id.tvContent);
        bottom.setOnClickListener(v -> initPop());
    }

    private void initPop() {
        List<ProjectTitleItemBean> listTop = new ArrayList<>();
        ProjectTitleItemBean bean = new ProjectTitleItemBean();
        bean.setName("请选择");
        bean.setChoose(false);
        listTop.add(bean);

        List<ProjectItemBean> listChild = new ArrayList<>();

        ProjectItemBean bean1 = new ProjectItemBean();
        bean1.setName("第一页");
        bean1.setChoose(false);
        bean1.setParent(null);
        bean1.setLevel(0);

        List<ProjectItemBean> listChild1 = new ArrayList<>();
        ProjectItemBean bean11 = new ProjectItemBean();
        bean11.setName("第1-1页");
        bean11.setChoose(false);
        bean11.setParent(bean1);


        List<ProjectItemBean> listChild11 = new ArrayList<>();
        ProjectItemBean bean111 = new ProjectItemBean();
        bean111.setName("第1-1-1页");
        bean111.setChoose(false);
        bean111.setParent(bean1);
        bean111.setChildList(null);
        bean111.setLevel(2);
        listChild11.add(bean111);

        ProjectItemBean bean112 = new ProjectItemBean();
        bean112.setName("第1-1-2页");
        bean112.setChoose(false);
        bean112.setParent(bean1);
        bean112.setChildList(null);
        bean112.setLevel(2);
        listChild11.add(bean112);

        bean11.setChildList(listChild11);
        bean11.setLevel(1);
        listChild1.add(bean11);


        ProjectItemBean bean12 = new ProjectItemBean();
        bean12.setName("第1-2页");
        bean12.setChoose(false);
        bean12.setParent(bean1);
        bean12.setChildList(null);
        bean12.setLevel(1);
        listChild1.add(bean12);
        bean1.setChildList(listChild1);
        listChild.add(bean1);

        ProjectItemBean bean2 = new ProjectItemBean();
        bean2.setName("第二页");
        bean2.setChoose(false);
        bean2.setParent(null);
        bean2.setLevel(0);

        List<ProjectItemBean> listChild2 = new ArrayList<>();
        ProjectItemBean bean21 = new ProjectItemBean();
        bean21.setName("第2-1页");
        bean21.setChoose(false);
        bean21.setParent(bean1);
        bean21.setChildList(null);
        bean21.setLevel(1);
        listChild2.add(bean21);
        ProjectItemBean bean22 = new ProjectItemBean();
        bean22.setName("第2-2页");
        bean22.setChoose(false);
        bean22.setParent(bean1);
        bean22.setChildList(null);
        bean22.setLevel(1);
        listChild2.add(bean22);
        bean2.setChildList(listChild2);
        listChild.add(bean2);


        BottomPopUtils.showPopWindow(listTop, listChild, MainActivity.this,result -> {
            tvContent.setText(result);
        });
    }
}

接下来是布局:

activity_main

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/btn_bottom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="点击弹框"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/tvContent"
        android:layout_marginTop="20dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/btn_bottom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</androidx.constraintlayout.widget.ConstraintLayout>

adapter_project

<?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_marginTop="10dp"
    android:background="#FFFFFF">

    <ImageView
        android:id="@+id/iv_select"
        android:visibility="invisible"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/pop_select"
        app:layout_constraintBottom_toBottomOf="@id/tv_name"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="@id/tv_name" />

    <TextView
        android:id="@+id/tv_name"
        android:layout_width="0dp"
        android:layout_height="40dp"
        android:layout_marginEnd="16dp"
        android:gravity="center_vertical"
        android:ellipsize="end"
        android:lines="1"
        android:textSize="18dp"
        app:layout_constraintEnd_toStartOf="@id/iv_select"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


</androidx.constraintlayout.widget.ConstraintLayout>

pop_time_line

<?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:gravity="center_horizontal"
    android:orientation="vertical">

    <TextView
        android:id="@+id/tv_name"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="7dp"
        android:paddingTop="8dp"
        android:paddingBottom="8dp"
        android:textSize="18dp"
        android:text="请选择"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@id/barrier"
        app:layout_constraintTop_toTopOf="parent" />

    <View
        android:id="@+id/view_circle_no"
        android:layout_width="5dp"
        android:layout_height="5dp"
        android:background="@drawable/circle_no"
        app:layout_constraintBottom_toBottomOf="@id/tv_name"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@id/tv_name" />

    <View
        android:visibility="gone"
        android:id="@+id/view_circle_yes"
        android:layout_width="5dp"
        android:layout_height="5dp"
        android:background="@drawable/circle_yes"
        app:layout_constraintBottom_toBottomOf="@id/tv_name"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@id/tv_name" />

    <androidx.constraintlayout.widget.Barrier
        android:id="@+id/barrier"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:barrierDirection="end"
        app:constraint_referenced_ids="view_circle_no,view_circle_yes" />


</androidx.constraintlayout.widget.ConstraintLayout>

popupwindow 我的时间线设计的有点问题,有点偏差对不准,欢迎各位大佬提点修改方法

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/popwindow_radius_bg"
    android:gravity="center_horizontal"
    android:orientation="vertical">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:id="@+id/iv_finish"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:paddingStart="10dp"
            android:paddingEnd="20dp"
            android:src="@mipmap/pop_finish"
            app:layout_constraintBottom_toBottomOf="@id/tv_title"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="@id/tv_title" />

        <TextView
            android:id="@+id/tv_title"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_marginTop="20dp"
            android:text="选择项目"
            android:textColor="#000000"
            android:textSize="18dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />


        <View
            android:id="@+id/view1"
            android:layout_width="0dp"
            android:layout_height="1dp"
            android:layout_marginTop="10dp"
            android:background="@color/cardview_dark_background"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/tv_title" />

        <View
            android:id="@+id/view2"
            android:layout_width="0dp"
            android:layout_height="1dp"
            android:layout_marginTop="10dp"
            android:background="@color/cardview_dark_background"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/rl_title" />

        <View
            android:id="@+id/view_line"
            android:layout_width="2dp"
            android:layout_height="0dp"
            android:layout_marginStart="22dp"
            android:layout_marginTop="18dp"
            android:layout_marginBottom="18dp"
            android:background="@color/cardview_dark_background"
            app:layout_constraintBottom_toBottomOf="@id/rl_title"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@id/rl_title" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rl_title"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="20dp"
            android:layout_marginEnd="20dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/view1" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rl"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:layout_marginStart="20dp"
            android:layout_marginEnd="20dp"
            app:layout_constraintTop_toBottomOf="@id/view2" />

    </androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>

接下来是drawable文件:

circle_no.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="100dp"/>

    <solid android:color="#FFFFFF" />

    <stroke
        android:width="1dp"
        android:color="@color/cardview_dark_background" />
</shape>

circle_yes.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="100dp"/>
    <solid android:color="@color/cardview_dark_background"/>
</shape>

popwindow_radius_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="14dp"/>
    <solid android:color="#FFFFFF" />
</shape>

接下来是anim,需要在res下创建anim文件夹,主要用作popwindow的弹出动画

pophidden_anim.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="300"
        android:fromYDelta="0"
        android:toYDelta="50%p" />
    <alpha
        android:duration="300"
        android:fromAlpha="1.0"
        android:toAlpha="0.0" />
</set>

popshow_anim.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha
        android:duration="300"
        android:fromAlpha="0.0"
        android:toAlpha="1.0" />

    <translate
        android:duration="300"
        android:fromYDelta="100%p"
        android:toYDelta="0" />
</set>

styles里面的代码

<resources>
    <style name="ipopwindow_anim_style">
        <item name="android:windowEnterAnimation">@anim/popshow_anim</item>
        <!-- 指定显示的动画xml -->
        <item name="android:windowExitAnimation">@anim/pophidden_anim</item>
        <!-- 指定消失的动画xml -->
    </style>
</resources>

还有两张图片没上传,是底部列表后面的对勾,还有popwindow的关闭按钮,这个你们自己找图片替换掉就行;

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/779589.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

JAVA-正则表达式基本语法规则和Pattern,Matcher,PatternSyntaxException三大类

目录 引言 一&#xff0c;正则表达式基本语法规则 二&#xff0c;正则表达式的三大类方法 2.1&#xff0c;Pattern类 2.1.1&#xff0c;Pattern的常用方法matches&#xff08;&#xff09; 2.2&#xff0c;Matcher类 2.2.1&#xff0c;Matcher的常用方法find() 2.2.2&a…

vue3-Vite原理

1. vite的优势 1. 极速的服务启动2. 轻量快速的预加载.....2. 对vite的理解&#xff08;和webpack对比说明&#xff09; webpack要经过打包&#xff0c;然后在开发阶段启动服务器vite不需要打包 下图的"准备"就是编译的意思。 css的内容会编译程一个字符串。 组件会…

[SSM]手写Spring框架

目录 十一、手写Spring框架 第一步&#xff1a;创建模块myspring 第二步&#xff1a;准备好要管理的Bean 第三步&#xff1a;准备myspring.xml配置文件 第四步&#xff1a;核心接口实现 第五步&#xff1a;实例化Bean 第六步&#xff1a;给Bean属性赋值 第七步&#xff…

arcgis-利用等高线数据生成dem栅格

1、打开cass&#xff0c;展高程点&#xff0c;绘制三角网&#xff0c;绘制等高线&#xff0c;删除三角网和高程点。如下&#xff1a; 2、得到的等高线图&#xff0c;如下&#xff1a; 3、保存文件为dwg格式&#xff0c;随后打开arcmap软件&#xff0c;打开dwg的线层数据&#x…

【项目设计】基于负载均衡的在线oj平台

目录 一、项目介绍 二、开发环境以及技术 三、概要设计 四、关键算法 五、项目演示 六、代码实现 一、项目介绍 该项目是基于负载均衡的在线oj&#xff0c;模拟平时刷题网站&#xff08;leetcode和牛客&#xff09;写的一个在线判题系统 项目主要分为五个模块&#xff…

DevOps系列文章之 Git知识大全

refs和reflog Git的所有操作都基于提交&#xff1a;你会暂存提交&#xff0c;创建提交&#xff0c;查看过去的提交记录&#xff0c;或者使用很多很多Git命令在不同的仓库之间转移提交内容。这些命令中的很大一部分都会以某种形式来操作提交&#xff0c;其中很多还会以提交ID作…

结构型设计模式之代理模式【设计模式系列】

系列文章目录 C技能系列 Linux通信架构系列 C高性能优化编程系列 深入理解软件架构设计系列 高级C并发线程编程 设计模式系列 期待你的关注哦&#xff01;&#xff01;&#xff01; 现在的一切都是为将来的梦想编织翅膀&#xff0c;让梦想在现实中展翅高飞。 Now everythi…

【iOS】对象底层学习

学习博客&#xff1a;[iOS]-OC对象底层探索 1. 类与对象 1.1 类和对象的本质 1.1.1 对象 对象的本质是结构体。 interface TestPerson : NSObject {// 成员变量// publicNSString *_age; // 4个字节 } property (nonatomic, copy) NSString *name; // 属性endimplementati…

C程序环境及预处理

​​​​​文章目录 一、程序的翻译环境和执行环境 1.程序编译过程 2.编译内部原理 3.执行环境 二、程序运行前的预处理 1.预定义符号归纳 2.define定义标识符 3.define定义宏 4.define替换规则 5.宏和函数的对比 三、头文件被包含的方式 四、练习&#xff1a;写一…

F.interpolate 数组采样操作

功能&#xff1a;利用插值方法&#xff0c;对输入的张量数组进行上\下采样操作&#xff0c;换句话说就是科学合理地改变数组的尺寸大小&#xff0c;尽量保持数据完整。 在计算机视觉中&#xff0c;interpolate函数常用于图像的放大(即上采样操作)。比如在细粒度识别领域中&…

【C#】MVC页面常见的重定向方式和场景

本篇文章主要简单讲讲&#xff0c;C# MVC 页面常见跳转或者重定向的方式和场景。 在实际项目开发中&#xff0c;在一些特定场景肯定会用到重定向&#xff0c;比如&#xff1a;不同角色跳转到不同视图地址 目录 一、种常见重定向方式1.1、RedirectToAction1.2、RedirectToRoute1…

猿人学14题—备而后动-勿使有变

猿人学14题—备而后动-勿使有变 抓包分析大致流程 mz参数生成m的值定位&参数组成补环境首先简单处理下十六进制编码问题提示&#xff1a;ReferenceError: window is not defined提示&#xff1a;document is not defined提示&#xff1a;$ is not definedASN1 is not defin…

【探索人工智能】我与讯飞星火认知大模型的对话

文章目录 讯飞星火认知大模型的地址概要讯飞星火认知大模型的发展历程讯飞星火认知大模型的主页利用讯飞星火大模型解决一些基本的数学问题讯飞星火认知大模型与OpenAI,ChatGPT没有关系&#xff01;让讯飞星火认知大模型编写传奇代码hello world小结 讯飞星火认知大模型的地址 …

chatgpt使用及辅助编程方面的体验

chatgpt使用及辅助编程方面的体验 文章目录 chatgpt使用及辅助编程方面的体验1 引言2 辅助编程体验2.1 辅助编写代码2.2 找出代码问题2.3 代码优化2.4 解释代码结束语 1 引言 最近几个月什么最火&#xff0c;那一定时chatgpt,虽然在国内使用存在各种限制&#xff0c;但是还是挡…

el-select和el-checkBox实现下拉菜单全选功能

el-select 和 el-checkbox 实现下拉菜单全选功能 示例代码&#xff1a; <el-selectpopper-class"select-container"v-model"ids"placeholder"请选择目标":multiple-limit"20"multiplefilterablecollapse-tagsclass"wd400&qu…

20230721 Essex UK, Dongbing Gu 公开讲座--机器人前沿

个人主页&#xff1a; https://www.essex.ac.uk/people/GUDON81301/dongbing-gu 机器人领域任务的特点&#xff1a;dull, dirty, dangerous tasks in remote spaces 机器鱼&#xff1a; 实时港口环境监测 机器鱼群探索算法 化学传感器 水面声呐定位系统/SLAM/通信问题 Robotic …

RocketMQ教程-安装和配置

Linux系统安装配置 64位操作系统&#xff0c;推荐 Linux/Unix/macOS 64位 JDK 1.8 Maven3.0 yum 安装jdk8 yum 安装maven 1.下载安装Apache RocketMQ RocketMQ 的安装包分为两种&#xff0c;二进制包和源码包。 点击这里 下载 Apache RocketMQ 5.1.3的源码包。你也可以从这…

网络安全 Day18-计算机网络知识03

计算机网络知识03 1. 路由器排查故障2. 设置和修改网关3. 设置修改DNS4. 私网地址5. VMware虚拟机NAT模式下上网原理6. DHCP工作原理 1. 路由器排查故障 排查网线&#xff0c;排查网卡&#xff0c;排查网卡的驱动查看网卡IP&#xff0c;没有配置IP、网关、DNS配置正确ping百度…

R语言贝叶斯METROPOLIS-HASTINGS GIBBS 吉布斯采样器估计变点指数分布分析泊松过程车站等待时间...

原文链接&#xff1a;http://tecdat.cn/?p26578 指数分布是泊松过程中事件之间时间的概率分布&#xff0c;因此它用于预测到下一个事件的等待时间&#xff0c;例如&#xff0c;您需要在公共汽车站等待的时间&#xff0c;直到下一班车到了&#xff08;点击文末“阅读原文”获取…

行为型模式 - 状态模式

概述 【例】通过按钮来控制一个电梯的状态&#xff0c;一个电梯有开门状态&#xff0c;关门状态&#xff0c;停止状态&#xff0c;运行状态。每一种状态改变&#xff0c;都有可能要根据其他状态来更新处理。例如&#xff0c;如果电梯门现在处于运行时状态&#xff0c;就不能进…