GridView、showDialog
来源:互联网 发布:生鲜网络平台 编辑:程序博客网 时间:2024/06/05 23:51
GridView
xml: <GridView android:layout_width="match_parent" android:layout_height="match_parent" android:numColumns="3" 列数 android:horizontalSpacing="5dp" 单元格的水平间距 android:verticalSpacing="5dp" 单元格的垂直间距 android:stretchMode="columnWidth" > 拉伸方式 </GridView>
在java中自己创建视图时需要通过要添加的目标容器的LayoutParams来配置布局参数(宽高、边距等等)
iv = new ImageView(GridViewActivity.this); iv.setScaleType(ScaleType.FIT_CENTER); // 添加宽高 AbsListView.LayoutParams lp = new AbsListView.LayoutParams( LayoutParams.MATCH_PARENT, 200); //运用布局参数 iv.setLayoutParams(lp); iv.setBackgroundColor(0xff333333);
弹出框
使用Activity自带的showDialog方法来显示
showDialog(100); //参数为id 这个方法调用之后Activity会去找有没有该id的Dialog,没有则触发onCreateDialog方法 protected Dialog onCreateDialog(int id) { //创建dialog if(id ==100){ return create2BtnDialog(); } return super.onCreateDialog(id); }
填充创建Dialog的逻辑 //弹出框的构造器 AlertDialog.Builder b = new AlertDialog.Builder(this); //组装弹出框标题 b.setTitle("两个按钮的弹出框"); //组装弹出框内容 b.setMessage(R.string.dialog_msg); //设置一个正向按钮 b.setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(LearnDialogActivity.this, "确定按钮被点击", 2000).show(); } }); b.setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(LearnDialogActivity.this, "取消按钮被点击", 2000).show(); } }); //创建Dialog对象 Dialog dialog = b.create();
自己来控制显示和隐藏,可以直接调用Dialog的show方法显示,dismiss方法或者cancel方法隐藏
if(null == twoBtnDialog){ twoBtnDialog = create2BtnDialog();}//显示弹出框twoBtnDialog.show();隐藏dialog.dismiss(); -->可以通过dialog.setOnDismissListener(listener)监听到或者dialog.cancel(); -->用dialog.setOnCancelListener(listener)监听
列表框,可以通过builder对象的setItems设置列表
final String[] items = {"打开","复制","剪切","重命名","删除","发送到"}; b.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { setTitle(items[which]); //处理列表点击的逻辑,which表示列表的下标 } });
针对字符串数组,可以在资源下通过定义
<string-array name="m_array"> <item>打开</item> 每个item表示一个数组项 <item>复制</item> </string-array>
java中获取数组资源
String[] ary = getResources().getStringArray(R.array.m_array);
Toast
Toast t = Toast.makeText(this, "我是一个提示,你只能看看", Toast.LENGTH_SHORT); //设置显示位置(相对位置,x方向的偏移,y方向的偏移) t.setGravity(Gravity.LEFT|Gravity.TOP, 50, 200); t.show();
自定义Toast
View layout = getLayoutInflater().inflate(R.layout.toast_layout, null); TextView tv = (TextView) layout.findViewById(R.id.toast_content); tv.setText("ABC"); Toast t = new Toast(getApplicationContext()); //Context上下文对象-->环境 //应用环境(组件窗口 服务) 窗口环境(Activity) //设置布局 t.setView(layout); t.setGravity(Gravity.CENTER, 0, 0); //设置事件 t.setDuration(Toast.LENGTH_LONG); t.show();
0 0
- GridView、showDialog
- showdialog
- showDialog
- showDialog
- ShowDialog
- ShowDialog
- ShowDialog 传值
- showDialog deprecated
- ShowDialog()应用
- show()、showDialog()
- showdialog funciton
- C# showdialog(this) 与showdialog()的区别
- show() and showDialog()
- showDialog回传值问题javascript
- show()与showdialog()区别
- showDialog缓存的问题
- Dispose close null showdialog
- 关闭window.showDialog()窗口
- 对tomcat来说,每一个进来的请求(request)都需要一个线程,直到该请求结束。
- 幽灵着色器
- cocos2dx中的cocosDenshion对不同平台音频支持格式
- 预编译宏指令#ifndef #endif解读
- XAMPP:Apache —— Error: Apache shutdown unexpectedly.
- GridView、showDialog
- 【洛谷P1004】方格取数
- C# list对象排序
- redis整合spring mybatis --缓存方案
- HTTP响应头和请求头信息对照表
- oracle12c安装时报错:[INS-30131] 执行安装程序验证所需的初始设置失败
- 设置Areas下的页面为项目默认起始页
- 简单的二维码的扫描
- 南阳 58题 最小步数