android游戏开发课程layout_…
16lz
2021-01-23
layout_weight的意义在于原有面积+剩下的部分 例如添加代码如下 android:id="@+id/btn_a" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/btn_a" android:layout_weight="1" /> android:id="@+id/btn_b" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="2" android:text="@string/btn_b"/> android:id="@+id/btn_c" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/btn_c" android:layout_weight="2" /> 这时在显示时就会按照1:2:2的面积显示 但是这是首先设置的height为自适应 假如把height设置为fill_parent就会出现如下情况 出现这种状况是因为三个Button的layout_height全部设为fill_parent 这其实与weight的原理有关,本来整个屏幕可以认为是1,但3个就需要3 可想而知剩下为1-3=-2 button1就变成了1(本来的fill_parent)+-2*1/5(剩下的)=3/5 button2 1-2/5 3 1-2/5 相当于3:1:1 也就是如图情况
更多相关文章
- android高级应用课程
- 关于接口类型的10篇课程推荐
- C++引用的意义与引用的本质
- 如何用C语言计算矩形的周长和面积?(附代码)
- C语言怎么计算矩形的面积和周长
- c语言如何计算圆面积和周长
- C语言中%d,%s,%x,%f,%.100的意义
- c语言如何求三角形的面积
- c语言实现输入圆的半径计算圆的面积