APP开发小贴士---问题虽小,但是需要注重
2010-11-20 13:42
246 查看
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-permission
android:name="android.permission.CHANGE_CONFIGURATION"/>
orientation =
this.getResources().getConfiguration().orientation;
在
activity里面重载
@Override
public
void
onConfigurationChanged(Configuration newConfig) {
super
.onConfigurationChanged(newConfig);
if
(
orientation
==
Configuration.
ORIENTATION_LANDSCAPE
) {
}
else
if
(
orientation
==
Configuration.
ORIENTATION_PORTRAIT
) {
}
}
---------------------------------------------------------------------------
保存上次的记录
spinner
使用
sharepreference
SharedPreferences
settings
;
Editor
editorsettings
;
public void onCreate(Bundle savedInstanceState) {
ArrayAdapter
adapterserver =
new
ArrayAdapter<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(
new
OnItemSelectedListener(){
@Override
public
void
onItemSelected(AdapterView<?> parent, View arg1,
int
postion,
long
id) {
editorsettings
.putInt(
"ServerNumPosition"
, postion);
editorsettings
.putString(
"ServerNum"
,
selectedServerName
);
editorsettings
.commit();
}
}
----------------------------------------------------------------------------------------------------------
判断
sdcard目录或者路径是否存在
:
public
void
checkPath(String pathname) {
try
{
String
sDStateString = android.os.Environment.getExternalStorageState
();
if
(sDStateString.equals(android.os.Environment.
MEDIA_MOUNTED
)) {
File
path =
new
File(pathname);
if
(!path.exists()){
if
(path.isDirectory()){
path.mkdirs();
//
创建目录
Toast.makeText
(
this
, pathname +
"has
existed"
, Toast.
LENGTH_LONG
).show();
}
else
if
(path.isFile())
{
path.createNewFile();
//
新建文件
}
}
}
}
catch
(Exception e)
{
System.
out
.println(
"error
for "
+
": "
+ e.getMessage());
}
}
相关文章推荐
- 想开发一款APP但是需要你的帮忙?
- 在开发手机APP之前需要考虑的5个问题
- 直播APP开发过程需要哪些技术和需要注意哪些问题?
- APP开发前需要理清的20个问题
- IOS7开发~App开发需要注意的一些问题
- APP开发前哪些问题需要解决?
- dcloud开发app手势登录,oppo手机需要点一下才显示手势画板的问题
- phonegap开发中IOS状态栏与APP重叠问题解决方法
- 开发APP不搞清楚这20个问题,必然沦为一场灾难
- webapp开发中的屏幕旋转问题
- 在iOS开发中,经常需要调用其它App,如拨打电话、发送邮件等。UIApplication:openURL:方法是实现这一目的的
- 混合app开发问题总结
- 直播APP开发成本大概需要多少?
- android:获取APP开发中需要的数据
- 一款android App需要考虑的问题:
- 时隔2年的一篇blog,给一些遇到此问题需要帮助的java me开发人员
- Android开发问题笔记(一):No resource found that matches the given name 'Theme.AppCompat.Light'.
- Web服务端开发需要考虑的问题(续)
- [iOS开发问题之联机调试问题]‘com.yourcompany.App_Name’ contains illegal character ‘_’.