PopupWindow详细介绍:
PopupWindow是一个以弹窗方式呈现的控件,可以用来显示任意视图(View),而且会浮动在当前活动(activity)的顶部”。因此我们可以通过PopupWindow实现各种各样的弹窗效果,PopupWindow自定义布局比较方便,而且在显示位置比较自由不受限制,因此受到众多开发者的青睐。
实现效果图:
关于实现这个功能准备以下几点:
1:在build.gradle中加入:compile 'com.jakewharton:butterknife:7.0.1'或者导入butterknife的jar包
在最早我们通常用findviewbyid来进行绑定控件,这里我用Butterkinfe注解的方式来绑定空件,AndroidStudio有一个(Zelezny)这个插件,可以使大家在日常开发中更有效的缩短时间,下面教大家如何安装Zelezny这个插件:
(1):打开Settings选择Plugins,点击Browse Repositories
(2):在搜索框中输入Zelezny,选择Android ButterKnife Zelezny,点击lnstall
(3):最后点击Restart Android Studio重新启动即可
2:安装完插件以后教大家如何使用,首先我们将布局展示给大家:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="@color/app_yellow">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="周边"
android:textColor="@color/whiter"
android:textSize="20dp" />
</android.support.v7.widget.Toolbar>
<!--从这里开始,即iushi自定义多条件-->
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#E2E2E2"></View>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@color/whiter"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/supplier_list_product"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/supplier_list_product_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="全部"
android:textSize="14dp" />
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:src="@mipmap/icon_arrow_down" />
</LinearLayout&