android入门1:有关布局与activity数据传递等
1.RelativeLayout布局
android:id="@+id/id1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
一般先定义id,用于之后的findViewById的操作。之后两个表示组件大小,其中wrap_content表示恰好包住内容,fill_parent和match_parent表示充满其parent组件,还有就是通过dp来定义大小。
android:layout_toRightOf = id
android:layout_alignBaseline = id
android:layout_alignParentTop = true
android:layout_centerInParent = true
之后定义其所在位置,以上都是几种比较代表的形式
android:layout_marginLeft
最后通过上面的这个dp进行微调
android:ems
定义EditText长度
暂时就看了这么多。
还有horizontal表水平,vertical表垂直。
2. activity传数值
一种是intent传,一种是bundle传。我用的是intent
activity1:
Intent intent = new Intent();
intent.setClass(ac1.this, ac2.class);
intent.putExtras(String, Object); //在字段里填充值
startActivity(intent);
//ac1.this.finish() 添加这个则不会返回
activity2:
Intent intent = getIntent();
String s = intent.getStringExtra("") //想要啥就getXXXExtra啥
PS:如何保留两位小数
DecimalFormat df=new DecimalFormat(".##");
df.format(doubleInstance);
之后我还需要多努力。
本文出自 “学习笔记” 博客,谢绝转载!
更多相关文章
- Android(安卓)Makefile中是 如何识别 TARGET_PRODUCT 的
- Android(安卓)UI线程和非UI线程
- Android(安卓)选择器 PickerView实例,时间选择器、地址选择器、单
- android的edittext怎么设置不默认被选中,edit默认不弹出
- [Android]定制RadioButton样式
- Android中ExpandableListView的使用
- CoordinatorLayout使用自定义Behavior实现UC浏览器顶栏效果
- 自定义 SeekBar 样式 详解
- android打开关闭屏幕