PopupWindow左边弹出菜单
博文快速操作栏效果如下:
需要在左边弹出来
核心代码如下:
View view = View.inflate(activity, R.layout.bw_item_fast_popupwindows, null); view.startAnimation(AnimationUtils.loadAnimation(activity, R.anim.slide_left_in)); setWidth(LayoutParams.WRAP_CONTENT); setHeight(LayoutParams.WRAP_CONTENT); setBackgroundDrawable(new BitmapDrawable()); setFocusable(true); setOutsideTouchable(true); setContentView(view); int[] location = new int[2]; parent.getLocationOnScreen(location); int x = location[0]-AppUtil.dip2px(activity, 70*3); showAtLocation(parent, Gravity.NO_GRAVITY, x, location[1]); //左边弹出 update();
public static int dip2px(Context context, float dipValue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (dipValue * scale + 0.5f); }
上面的70*3表示弹出菜单的宽度,每个项为70dp
bw_item_fast_popupwindows.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="match_parent" > <LinearLayout android:id="@+id/ll_popup" android:layout_width="wrap_content" android:layout_height="@dimen/height_top_smallbar" android:layout_centerVertical="true" android:background="@drawable/bw_fast_pop_bg" android:paddingTop="5dp" android:paddingBottom="5dp" android:orientation="horizontal" > <RelativeLayout android:id="@+id/rl_bw_item_praise" android:layout_width="70dp" android:layout_height="match_parent" android:layout_weight="1" > <TextView android:id="@+id/bw_item_praise" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_centerInParent="true" android:drawableLeft="@drawable/praise_white" android:drawablePadding="2dp" android:gravity="center_vertical" android:text="@string/bw_item_praise" android:textColor="@color/white" android:textSize="@dimen/snormalSize" /> </RelativeLayout> <RelativeLayout android:id="@+id/rl_bw_item_comment" android:layout_width="70dp" android:layout_height="match_parent" android:layout_weight="1" > <View android:layout_width="0.5dp" android:layout_height="match_parent" android:background="@color/line_fast_bw" /> <TextView android:id="@+id/bw_item_comment" android:layout_width="wrap_content" android:layout_height="match_parent" android:drawableLeft="@drawable/comment_white" android:drawablePadding="2dp" android:layout_centerInParent="true" android:gravity="center_vertical" android:text="@string/bw_item_comment" android:textColor="@color/white" android:textSize="@dimen/snormalSize" /> </RelativeLayout> <RelativeLayout android:id="@+id/rl_bw_item_fav" android:layout_width="70dp" android:layout_height="match_parent" android:layout_weight="1" > <View android:layout_width="0.5dp" android:layout_height="match_parent" android:background="@color/line_fast_bw" /> <TextView android:id="@+id/bw_item_fav" android:layout_width="wrap_content" android:layout_height="match_parent" android:drawableLeft="@drawable/collection_white" android:drawablePadding="2dp" android:layout_centerInParent="true" android:gravity="center_vertical" android:text="@string/bw_item_fav" android:textColor="@color/white" android:textSize="@dimen/snormalSize" /> </RelativeLayout> </LinearLayout> </RelativeLayout>
最终如第一张图
相关推荐
thisisid 2019-06-28
OliverLau 2019-06-21
Miryou 2019-06-21
jsonnan 2015-07-10
laose0 2014-10-26
MrDuoduo 2014-06-05
Geeny 2014-04-04
刘炳昭 2012-07-04
magic00 2012-05-22
scott0 2012-01-17
Tom天天 2011-12-03
Ifree团队 2011-10-27
bible 2011-10-12
python大数据 2011-04-14
peixiaopao 2011-04-08
lumitzs 2011-03-31