APP开发小贴士---问题虽小,但是需要注重
来源:互联网 发布:黑暗骑士崛起 知乎 编辑:程序博客网 时间:2024/05/02 01:56
Android自定义对话框的大小
在Android做界面时要弹出对话框让用户输入内容,经常遇到开始的时候没有内容对话框一点点,看起来很别扭,查了下资料,修改对话框的WindowManager.LayoutParams可以达到修改对话框大小的目的.
从Dialog继承一个自定义对话框类,在其构造函数中加上如下代码:
WindowManager m = getWindowManager();
Display d = m.getDefaultDisplay(); //为获取屏幕宽、高
LayoutParams p = getWindow().getAttributes(); //获取对话框当前的参数值
p.height = (int) (d.getHeight() * 0.6); //高度设置为屏幕的0.6
p.width = (int) (d.getWidth() * 0.95); //宽度设置为屏幕的0.95
getWindow().setAttributes(p); //设置生效
直接创建dialog对象例子代码:
dialog = new Dialog(this,R.style.FullHeightDialog);
dialog.setContentView(R.layout.transferdialog);
WindowManager m= dialog.getWindow().getWindowManager();
Display d =m.getDefaultDisplay();
dialog.getWindow().getAttributes().height = (int) (d.getHeight()* 0.6);
dialog.getWindow().getAttributes().width = (int) (d.getWidth()* 0.9);
dialog.getWindow().setAttributes(dialog.getWindow().getAttributes());
---------------------------------------------------------------------
小贴士: 若是屏幕旋转时,会重新执行onCreat().修改的办法就是在ANDROIDMAINFEST.XML的activity下面加入
android:configChanges=”orientation|keyboardHidden”
<uses-permissionandroid:name="android.permission.CHANGE_CONFIGURATION"/>
orientation =this.getResources().getConfiguration().orientation;
在activity里面重载@Override
public voidonConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (orientation ==Configuration.ORIENTATION_LANDSCAPE) {
}
else if (orientation ==Configuration.ORIENTATION_PORTRAIT) {
}
}
---------------------------------------------------------------------------
保存上次的记录spinner
使用sharepreference
SharedPreferencessettings;
Editor editorsettings;
public void onCreate(Bundle savedInstanceState) {
ArrayAdapter adapterserver =newArrayAdapter<String>(
this,android.R.layout.simple_spinner_item, keyServers);
adapterserver.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapterserver);
settings =getSharedPreferences("preferences_settings",Context.MODE_PRIVATE);
editorsettings = settings.edit();
spinner.setSelection(settings.getInt("ServerNumPosition", 0)); //line
spinner.setOnItemSelectedListener(newOnItemSelectedListener(){
@Override
public voidonItemSelected(AdapterView<?> parent, View arg1,
int postion, long id) {
editorsettings.putInt("ServerNumPosition", postion); editorsettings.putString("ServerNum", selectedServerName);
editorsettings.commit();
}
}
----------------------------------------------------------------------------------------------------------
判断sdcard目录或者路径是否存在:
public voidcheckPath(String pathname) {
try{
StringsDStateString = android.os.Environment.getExternalStorageState();
if(sDStateString.equals(android.os.Environment.MEDIA_MOUNTED)) {
Filepath = new File(pathname);
if(!path.exists()){
if(path.isDirectory()){
path.mkdirs(); //创建目录
Toast.makeText(this, pathname + "hasexisted", Toast.LENGTH_LONG).show();
}
else if(path.isFile())
{
path.createNewFile(); //新建文件
}
}
}
}catch(Exception e)
{
System.out.println("errorfor " + ": "
+ e.getMessage());
}
}
- APP开发小贴士---问题虽小,但是需要注重
- APP开发注重用户体验
- APP运营需要注重的细节
- 前端开发需要注重的几个方面
- 开发一个app需要考虑的问题
- 关于android app不注重过度绘制问题
- IOS7开发~App开发需要注意的一些问题
- 开发app需要角色
- APP开发前需要理清的20个问题
- 想开发一款APP但是需要你的帮忙?
- 做友情链接需要注重什么
- 在SSH2开发中需要注意的一个小问题。
- thinkphp开发中你需要注意的一些小问题
- APP开发小知识点
- APP开发究竟需要多少钱?
- 开发一个APP需要多少钱?
- 开发一款APP需要多少钱?
- 需要注意的小问题
- 金额 输入校验 正则表达式
- Android 中压力测试工具Monkey的用法
- Java回调函数
- QMenu上icon的大小设置
- 简单操作权限就一个函数足够了,甚至5-6个表足够可以了,没必要搞那么复杂,也没必要瞎搞误人子弟啊
- APP开发小贴士---问题虽小,但是需要注重
- Java 解析XML 之 DOM4J 解析 XML 分析测试
- C#编程指令的好处和用法
- 设计模式-职责链模式
- Google Chrome下Flash Player Debug失效
- Sql Server 常用日期格式转换
- PHP5版本的讲解
- 移动互联网袭来 如何成为一个android开发者
- 移动互联网袭来 如何成为一个android开发者