day5ImageView LinearLayout.docx
- 文档编号:27403929
- 上传时间:2023-06-30
- 格式:DOCX
- 页数:15
- 大小:441.62KB
day5ImageView LinearLayout.docx
《day5ImageView LinearLayout.docx》由会员分享,可在线阅读,更多相关《day5ImageView LinearLayout.docx(15页珍藏版)》请在冰豆网上搜索。
day5ImageViewLinearLayout
1、图片视图
图片容器:
可以来源于assets,res,甚至Web;
凡是放在drawable中的图片了,都会在R.java中生成对应的ID;
图片命名:
a-z,0-9
2、ScaleType:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
android: id="@+id/dogId" android: layout_width="200dp" android: layout_height="200dp" android: background="#FF0000" android: src="@drawable/dog" android: scaleType="matrix" //左上角对齐 android: scaleType="fitXY" //对齐整个控件 android: scaleType="fitStart" //对齐上边界 android: scaleType="fitCenter" //图片尺寸原比例缩放,对齐中间 android: scaleType="fitEnd" //对下下边界 android: scaleType="center" //图片不缩放,以图片为中心,截取控件大小 android: scaleType="centerCorp" //围绕控件大小进行缩放 android: scaleType="centerInside" /> //图片最大边,适应控件 来自< 1 2 3 4 5 imageView = (ImageView)findViewById(R.id.imageView2Id); imageView.setScaleType(ScaleType.CENTER); imageView.setImageResource(R.drawable.imageName); 来自< 3、LinearLayout布局的嵌套: 就近原则; 控件标签的使用; 4、layout_weight属性: 1)子控件并未占满父控件的情况下,才有效; 2)用于指定空闲空间的分配比例;不是整个子控件的比例,而是追加的空间; 3)将子控件原始值设置为0dp,然后分配空闲空间,就能实现子控件按比例分割父控件; 5、Stone、Scissors、Cloth游戏界面布局: 6、界面分析: 1)标题区: 直接放置一个TextView即可; 文字居中: android: gravity="center"; 2)选手区: 外置一个LinearLayout,方向设置为horizontal,宽度利用layout_weight平分父控件,高度wrap_content; 然后,放置一个ImageView,高度和宽度都wrap_content,或者计算好dp,设置一个大小; 其次,放置一个RadioGroup,方向为Vertical,宽度match_parent,高度wrap_content; 最后,放置3个RadioButton; 3)确定区: Button控件即可 4)结果判定区: 放置一个Linear,里面横向排列2个TextView; Tips: 实际编写顺序: 1)标题区;-->3)确定区;-->4)结果判定区;-->2)选手区 代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 android=" xmlns: tools=" android: layout_width="match_parent" android: layout_height="match_parent" android: orientation="vertical" tools: context="com.example.day5_linearlayout.MainActivity" > -- 标题区: Guess Game --> android: layout_width="match_parent" android: layout_height="wrap_content" android: textSize="20sp" android: gravity="center" android: text="Guess Game"/> -- 选手区 : 左右2栏--> android: layout_width="match_parent" android: layout_height="wrap_content" android: orientation="horizontal"> -- 左边选手: 汪星人 --> android: layout_width="0dp" android: layout_height="wrap_content" android: layout_weight="1" android: background="#FFFF00" android: orientation="vertical"> android: layout_width="match_parent" android: layout_height="0dp" android: layout_weight="2" android: id="@+id/dogId" android: src="@drawable/dog" android: scaleType="fitXY" android: layout_margin="10dp"/> android: layout_width="match_parent" android: layout_height="0dp" android: layout_weight="3" android: orientation="vertical"> android: layout_width="match_parent" android: layout_height="0dp" android: layout_weight="1" android: text="Stone"/> android: layout_width="match_parent" android: layout_height="0dp" android: layout_weight="1" android: text="Scissors"/> android: layout_width="match_parent" android: layout_height="0dp" android: layout_weight="1" android: text="Cloth"/> -- 右边选手: 佛祖 --> android: layout_width="0dp" android: layout_height="wrap_content" android: layout_weight="1" android: background="#FFFF00" android: orientation="vertical"> android: layout_width="match_parent" android: layout_height="0dp" android: layout_weight="2" android: id="@+id/nobugId" android: src="@drawable/dog" android: scaleType="fitXY" android: layout_margin="10dp"/> android: layout_width="match_parent" android: layout_height="0dp" android: layout_weight="3" android: orientation="vertical"> android: layout_width="match_parent" android: layout_height="0dp" android: layout_weight="1" android: text="Stone"/> android: layout_width="match_parent" android: layout_height="0dp" android: layout_weight="1" android: text="Scissors"/> android: layout_width="match_parent" android: layout_height="0dp" android: layout_weight="1" android: text="Cloth"/> -- 确认区 --> 来自< 实际结果展示: 2015/5/2821: 58-屏幕剪辑 7、RelativeLayout: 以父控件或者子控件为参考,决定自身的位置; 更方便; 第一控件总是默认放在左上角; 8、RelativeLayout的好处: LinearLayout嵌套层次太深,解析费资源; 9、RelativeLayout的两组常用属性: 两个控件的实质关系还是兄弟控件 1)参考控件作为兄控件,放置在参考控件的外侧: 1 2 3 4 android: layout_below = "@id/xx" android: layout_above = "@id/xx" android: layout_toLeftOf = "@id/xx" android: layout_toRightOf = "@id/xx" 来自< 2)参考控件作为父控件: 1 2 3 4 android: layout_alignLeft = "@id/xx" android: layout_alignRight = "@id/xx" android: layout_alignTop = "@id/xx" android: layout_alignBottom = "@id/xx" 来自< 3)与前面两组属性组合使用的属性: android: layout_alignBaseline="@id/xx" 10、对齐至控件的基准线: 两个控件的基准线在同一条线上 基准线 11、与父控件的4个边缘对齐 1 2 3 4 android: layout_alignParentLeft = "@id/xx" android: layout_alignParentRight = "@id/xx" android: layout_alignParentTop = "@id/xx" android: layout_alignParentBottom = "@id/xx" 12、对齐至父控件的中央 1 2 3 android: layout_centerInParent = "@id/xx" android: layout_centerHorizontal = "@id/xx" android: layout_centerVertical = "@id/xx" 13、
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- day5ImageView LinearLayout
![提示](https://static.bdocx.com/images/bang_tan.gif)