项目中经常需要底部弹出框,这里我整理一下其中我用的比较顺手的一个方式(底部弹出一个横向满屏的dialog)。
效果图如下所示(只显示关键部分):
步骤如下所示:
1.定义一个dialog的布局(lay_share.xml)
1 <?xml version="1.0" encoding="utf-8"?> 2 3 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent" 6 android:background="@color/white" 7 android:orientation="vertical"> 8 9 <LinearLayout 10 android:layout_width="match_parent" 11 android:layout_height="wrap_content" 12 android:gravity="center_vertical" 13 android:orientation="horizontal" 14 android:paddingBottom="@dimen/padding_15" 15 android:paddingTop="@dimen/padding_15"> 16 17 <View 18 android:layout_width="0dp" 19 android:layout_height="0dp" 20 android:layout_weight="1" /> 21 22 <TextView 23 android:layout_width="wrap_content" 24 android:layout_height="wrap_content" 25 android:drawablePadding="@dimen/padding_5" 26 android:drawableTop="@mipmap/ic_weixin_share" 27 android:gravity="center" 28 android:text="微信" 29 android:textColor="@color/color_999999" 30 android:textSize="@dimen/text_14" /> 31 32 <View 33 android:layout_width="0dp" 34 android:layout_height="0dp" 35 android:layout_weight="1" /> 36 37 <TextView 38 android:layout_width="wrap_content" 39 android:layout_height="wrap_content" 40 android:drawablePadding="@dimen/padding_5" 41 android:drawableTop="@mipmap/ic_circle_share" 42 android:gravity="center" 43 android:text="朋友圈" 44 android:textColor="@color/color_999999" 45 android:textSize="@dimen/text_14" /> 46 47 <View 48 android:layout_width="0dp" 49 android:layout_height="0dp" 50 android:layout_weight="1" /> 51 52 <TextView 53 android:layout_width="wrap_content" 54 android:layout_height="wrap_content" 55 android:drawablePadding="@dimen/padding_5" 56 android:drawableTop="@mipmap/ic_weibo_share" 57 android:gravity="center" 58 android:text="微博" 59 android:textColor="@color/color_999999" 60 android:textSize="@dimen/text_14" /> 61 62 <View 63 android:layout_width="0dp" 64 android:layout_height="0dp" 65 android:layout_weight="1" /> 66 </LinearLayout> 67 68 <View 69 android:layout_width="match_parent" 70 android:layout_height="0.5dp" 71 android:layout_marginLeft="@dimen/padding_10" 72 android:layout_marginRight="@dimen/padding_10" 73 android:background="@color/color_c9c9c9" /> 74 75 <TextView 76 android:id="@+id/tv_cancel" 77 android:layout_width="match_parent" 78 android:layout_height="wrap_content" 79 android:gravity="center" 80 android:padding="@dimen/padding_15" 81 android:text="取消" 82 android:textColor="@color/color_666666" 83 android:textSize="@dimen/text_18" /> 84 </LinearLayout>