底部菜单实现(Dialog方案)
项目中经常会要实现在屏幕底部弹出一个窗口,比如一个分享窗口:

下面详解实现步骤:
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方案)的更多相关文章
- Vue 在手机上键盘把底部菜单顶上去的解决方案
Vue 在手机上键盘把底部菜单顶上去的解决方案 ios和安卓的键盘的区别 ios和安卓的键盘的区别弹起方式不同, ios直接弹出键盘, 不影响页面, 而安卓键盘弹起时会把页面顶起来, 这样就会把底部菜 ...
- Android 底部弹出Dialog(横向满屏)
项目中经常需要底部弹出框,这里我整理一下其中我用的比较顺手的一个方式(底部弹出一个横向满屏的dialog). 效果图如下所示(只显示关键部分): 步骤如下所示: 1.定义一个dialog的布局(lay ...
- Android底部菜单的实现
前言:以前制作菜单使用TabHost,但是android 3.0以上就被废弃了,google已经不建议使这个类了.ActionBar也是菜单,不过在头部,算是导航了 ===本文就介绍怎么制作底部菜单= ...
- 转-Fragment+FragmentTabHost组件(实现新浪微博底部菜单)
http://www.cnblogs.com/lichenwei/p/3985121.html 记得之前写过2篇关于底部菜单的实现,由于使用的是过时的TabHost类,虽然一样可以实现我们想要的效果, ...
- 转-TabHost组件(一)(实现底部菜单导航)
http://www.cnblogs.com/lichenwei/p/3974009.html 什么是TabHost? TabHost组件的主要功能是可以进行应用程序分类管理,例如:在用户使用wind ...
- 转-TabHost组件(二)(实现底部菜单导航)
http://www.cnblogs.com/lichenwei/p/3975095.html 上面文章<安卓开发复习笔记——TabHost组件(一)(实现底部菜单导航)>中提到了利用自定 ...
- Android应用主界面底部菜单实现
介绍 现在绝大多数主流的应用主界面,都会包含一个底部菜单,就拿腾讯的QQ与微信来说,看起来是这样的 <---我是底部菜单 原理 在很久以前,可以通过TabActivity实现相关功能,自从Fr ...
- Android自定义控件系列(四)—底部菜单(下)
转载请注明出处:http://www.cnblogs.com/landptf/p/6290862.html 在app中经常会用到底部菜单的控件,每次都需要写好多代码,今天我们用到了前几篇博客里的控件来 ...
- Android中软键盘弹出时底部菜单上移问题
当在Android的layout设计里面如果输入框过多,则在输入弹出软键盘的时候,下面的输入框会有一部分被软件盘挡住,从而不能获取焦点输入. 解决办法: 方法一:在你的activity中的oncrea ...
- [Android] Android 使用 FragmentTabHost + Fragment 实现 微信 底部菜单
Android 使用 FragmentTabHost + Fragment 实现 微信 底部菜单 利用FragmentTabHost实现底部菜单,在该底部菜单中,包括了4个TabSpec,每个TabS ...
随机推荐
- bzoj 3111 蚂蚁 动态规划
题目描述 在一个 n*m 的棋盘上,每个格子有一个权值,初始时,在某个格子的顶点处一只面朝北的蚂蚁,我们只知道它的行走路线是如何转弯,却不知道每次转弯前走了多长. 蚂蚁转弯是有一定特点的,即它的转弯序 ...
- 7月10日day2总结
今天学习过程和小结 上午: java项目建立方法,maven Tomcat的部署和MySQL的安装与权限. 分配时中datanote和namenote DataNode 作用 1Data Node以数 ...
- 开启和关闭mysql服务
@echo offfor /f "skip=3 tokens=4" %%i in ('sc query MySQLa') do set "zt=%%i" &am ...
- <a></a>的href属性失效
<a href="javascript:void(0);" class="close">关闭</a>
- POJ1018 Communication System
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26738 Accepted: 9546 Description We ...
- [ CodeVS冲杯之路 ] P1011
不充钱,你怎么AC? 题目:http://codevs.cn/problem/1011/ 一开始以为是道数学题,列出了一个公式 后面验证,发现只能推出第一次,后面的还需要迭代,推翻这个公式 又去瞟了一 ...
- F28379D烧写双核程序(在线&离线)
烧写双核程序前需知在分别对F28379D的CPU1和CPU2两个核进行烧写程序时,需要在CCS中建立两个工程,独立编写两个核的程序.如controlSUITE中提供的双核程序例程: 1. 在线1.1 ...
- msvc/gcc:中用#pragma指令关闭特定警告(warning)
在使用一些第三方库或源码的时候,经常会遇到编译时产生warnings情况,这些warning不是我们自己的代码产生的,当然也不好去修改,但每次编译都显示一大堆与自己代码无关的警告也着实看着不爽,更麻烦 ...
- mogilefsd同步速度调优
#查看主从mogadm settings list #一点点调试mogadm settings listmogadm settings set internal_queue_limit 500moga ...
- 学习hibernate,这个系列很不错
从这里入,感谢作者啊. 看了很多资料,这个是最能让我入门的.感觉. http://blog.csdn.net/yerenyuan_pku/article/details/52745486