项目中经常会要实现在屏幕底部弹出一个窗口,比如一个分享窗口:

下面详解实现步骤:

1.定义布局

<?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="wrap_content"
android:background="@color/white"
android:gravity="center_horizontal"
android:orientation="vertical"> <com.piston.usedcar.widget.KiloPiker
android:id="@+id/kp_car_grad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"/> <TextView
android:id="@+id/tv_sel_car_grad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/theme_gray_bg"
android:gravity="center"
android:padding="@dimen/common_padding_less"
android:text="确定"
android:textColor="@color/theme_gray_text"
android:textSize="@dimen/text_small"/>
</LinearLayout>

2.定义从底部弹出的动画

  a.弹出动画dialog_enter.xml

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromYDelta="100%p">
</translate>

  b.退出动画dialog_exit.xml

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:toYDelta="100%p">
</translate>

3.在styles.xml定义动画样式

    <style name="MyDialogAnimationStyle" parent="android:Animation">
<item name="@android:windowEnterAnimation">@anim/dialog_enter</item>
<item name="@android:windowExitAnimation">@anim/dialog_exit</item>
</style>

4.防止dialog有边距,以便dialog填充整个屏幕宽度,定义如下样式:

<style name="common_dialog" parent="@android:style/Theme.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
</style>

5.代码实现:

        View view = LayoutInflater.from(AppContext.getContext()).inflate(R.layout.dialog_bottom_car_grad, null);
final Dialog dialog = new Dialog(this, R.style.common_dialog);
dialog.setContentView(view);
dialog.getWindow().setWindowAnimations(R.style.MyDialogAnimationStyle);
dialog.show(); final KiloPiker kpCarGrad = (KiloPiker) view.findViewById(R.id.kp_car_grad);
TextView mViewPengyou = (TextView) view.findViewById(R.id.tv_sel_car_grad); kpCarGrad.setNumberPickerDividerColor(kpCarGrad, R.color.background_split); kpCarGrad.setDisplayedValues(CAR_GRAD_ARRAY);
kpCarGrad.setMaxValue(CAR_GRAD_ARRAY.length - 1);
kpCarGrad.setMinValue(0); kpCarGrad.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
carGradSelPos = newVal;
}
}); mViewPengyou.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (carGradSelPos == 0) {
tvSynthCarGrad.setText("优秀车况");
} else if (carGradSelPos == 1) {
tvSynthCarGrad.setText("良好车况");
}
dialog.dismiss();
}
}); // 设置相关位置,一定要在 show()之后
Window window = dialog.getWindow();
window.getDecorView().setPadding(0, 0, 0, 0);
WindowManager.LayoutParams params = window.getAttributes();
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.gravity = Gravity.BOTTOM;
window.setAttributes(params);

  

底部菜单实现(Dialog方案)的更多相关文章

  1. Vue 在手机上键盘把底部菜单顶上去的解决方案

    Vue 在手机上键盘把底部菜单顶上去的解决方案 ios和安卓的键盘的区别 ios和安卓的键盘的区别弹起方式不同, ios直接弹出键盘, 不影响页面, 而安卓键盘弹起时会把页面顶起来, 这样就会把底部菜 ...

  2. Android 底部弹出Dialog(横向满屏)

    项目中经常需要底部弹出框,这里我整理一下其中我用的比较顺手的一个方式(底部弹出一个横向满屏的dialog). 效果图如下所示(只显示关键部分): 步骤如下所示: 1.定义一个dialog的布局(lay ...

  3. Android底部菜单的实现

    前言:以前制作菜单使用TabHost,但是android 3.0以上就被废弃了,google已经不建议使这个类了.ActionBar也是菜单,不过在头部,算是导航了 ===本文就介绍怎么制作底部菜单= ...

  4. 转-Fragment+FragmentTabHost组件(实现新浪微博底部菜单)

    http://www.cnblogs.com/lichenwei/p/3985121.html 记得之前写过2篇关于底部菜单的实现,由于使用的是过时的TabHost类,虽然一样可以实现我们想要的效果, ...

  5. 转-TabHost组件(一)(实现底部菜单导航)

    http://www.cnblogs.com/lichenwei/p/3974009.html 什么是TabHost? TabHost组件的主要功能是可以进行应用程序分类管理,例如:在用户使用wind ...

  6. 转-TabHost组件(二)(实现底部菜单导航)

    http://www.cnblogs.com/lichenwei/p/3975095.html 上面文章<安卓开发复习笔记——TabHost组件(一)(实现底部菜单导航)>中提到了利用自定 ...

  7. Android应用主界面底部菜单实现

    介绍 现在绝大多数主流的应用主界面,都会包含一个底部菜单,就拿腾讯的QQ与微信来说,看起来是这样的  <---我是底部菜单 原理 在很久以前,可以通过TabActivity实现相关功能,自从Fr ...

  8. Android自定义控件系列(四)—底部菜单(下)

    转载请注明出处:http://www.cnblogs.com/landptf/p/6290862.html 在app中经常会用到底部菜单的控件,每次都需要写好多代码,今天我们用到了前几篇博客里的控件来 ...

  9. Android中软键盘弹出时底部菜单上移问题

    当在Android的layout设计里面如果输入框过多,则在输入弹出软键盘的时候,下面的输入框会有一部分被软件盘挡住,从而不能获取焦点输入. 解决办法: 方法一:在你的activity中的oncrea ...

  10. [Android] Android 使用 FragmentTabHost + Fragment 实现 微信 底部菜单

    Android 使用 FragmentTabHost + Fragment 实现 微信 底部菜单 利用FragmentTabHost实现底部菜单,在该底部菜单中,包括了4个TabSpec,每个TabS ...

随机推荐

  1. Create Windows Server 2008 cluster from the command line

    How to create a Windows Server 2008 cluster from the command line? Creating a cluster in Server 2008 ...

  2. iOS-android-windowsphone等移动终端平台开发流程图

    到了公司后,半个月时间就是在熟悉下面这张图里的流程, 项目流程图:     下面是我对这张图的一些理解:        

  3. jquery验证前端页面

    一共三个页面 jquery.html文件(前端页面,jquery验证用户信息) jquerytest.php文件(后台处理页面) jquerydb.php文件(数据库) 数据表结构 jquery.ht ...

  4. Android 显示或隐藏标题栏进度条TitleProgressBar

    1.新建项目,布局文件如下:activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/ ...

  5. MSSQL-字符串分离与列记录合并成一行混合使用

    一般我们在数据库的表字段存储字典Id,如果有多个的话一般是用,或分隔符分隔(12,14),列表显示的时候是显示字典名,那如果要在数据库将字典Id转成用户看得懂的字典名,该怎么办呢? 我们这时候可以结合 ...

  6. CF978B File Name【数组操作/序列判断连续出现>=3次的‘x’个数】

    CF978B File Name [分析]:设置计数器cnt,计数x的个数:遇到非x,若cnt>=3的话累加多出的个数,计数器清零:若最后cnt>=3说明没遇到非x无法清零,那后部分就都是 ...

  7. Python_Tips[4] -> and 和 or 的计算原则

    and和or / and & or 对于and和or,可以连接多个值,其分别遵循原则: 全是 And: 返回第一个遇到的无效值,若全有效,返回最后一个有效值 全是 Or: 返回第一个遇到的有效 ...

  8. 由"软件是干什么的"引发的思考

            自工作以来,都只在进行模块的开发,很少站在整个项目的角度思考过.甚至,自己开发的软件,自己都没有去用过,包括开发的一些APP,都没有下载来认真体验过.思考过.却对自己手机上那些用过的A ...

  9. Android Developer -- Bluetooth篇 开发实例之三 管理连接

    Managing a Connection When you have successfully connected two (or more) devices, each one will have ...

  10. PHP生成GUID的函数

    GUID: 即Globally Unique Identifier(全球唯一标识符) 也称作 UUID(Universally Unique IDentifier) . GUID是一个通过特定算法产生 ...