LinearLayout的layout_weight问题导致手机无法显示全部控件
2013-05-05 21:21
399 查看
今天遇到个难缠的问题,Android界面一直都不是那么好设计,今天体会到了
对应的layout文件如下:
运行效果却很悲剧
上面一小部分始终显示不出来,中间那个View为什么那么不肯妥协,非要占据上面的位置。
这个问题困扰了我很长时间,问了很多人,有的说用RelativeLayout,但是我还是没有找到很好的解决方案
后来上网查资料发现LinearLayout的layout_weight属性是成反比的,跟空间的大小分配刚好是相反的
当时没太注意,后来百般无奈后,偶然间修改了那个View的layout的layout_weight
运行下一看,好像有点变化,通过LogCat观察出
每当我增大layout_weight时,onSizeChanged: width 35.5557:,height: 从45.33332逐渐减小到36.5557
慢慢的,上面犹抱琵琶半遮面的Chronometer空间终于露出来了
效果如图
通过这几天的Android编程,感觉编程有的时候真的很苦逼,你常常为了一个奇怪的问题,茶不思饭不想,水不喝了,厕所不上了,妹子不找了,就一心想着这个问题弄不出来就一直弄下去
但是当你解决问题时,那种感觉又是很美妙的,OK,编程还是要继续下去!!!
对应的layout文件如下:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_margin="0dip" android:layout_weight="1"> <TextView android:text="@string/cost_time" android:layout_gravity="left" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1"/> <Chronometer android:id="@+id/costTime" android:gravity="left" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_margin="0dip" android:layout_weight="1"/> <TextView android:text="@string/best_time" android:gravity="center" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_margin="0dip" android:layout_weight="1"/> <TextView android:id="@+id/best_time" android:text="@string/default_time" android:layout_gravity="right" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1"/> </LinearLayout> <LinearLayout android:id="@+id/puzzleview" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_weight="8"> </LinearLayout> <LinearLayout android:id="@+id/utilbtn_layout" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="horizontal"> <Button android:id="@+id/undo_button" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/undo_button" android:layout_weight="1"/> <Button android:id="@+id/erase_button" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/erase_button" android:layout_weight="1"/>" </LinearLayout> <LinearLayout android:id="@+id/num_layout" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="horizontal"> <Button android:id="@+id/Button1" android:text="1" android:gravity="center" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="0dip" android:layout_weight="1"/> <Button android:id="@+id/Button2" android:text="2" android:gravity="center" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="0dip" android:layout_weight="1"/> <Button android:id="@+id/Button3" android:text="3" android:gravity="center" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="0dip" android:layout_weight="1"/> <Button android:id="@+id/Button4" android:text="4" android:gravity="center" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="0dip" android:layout_weight="1"/> <Button android:id="@+id/Button5" android:text="5" android:gravity="center" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="0dip" android:layout_weight="1"/> <Button android:id="@+id/Button6" android:text="6" android:gravity="center" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="0dip" android:layout_weight="1"/> <Button android:id="@+id/Button7" android:text="7" android:gravity="center" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="0dip" android:layout_weight="1"/> <Button android:id="@+id/Button8" android:text="8" android:gravity="center" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="0dip" android:layout_weight="1"/> <Button android:id="@+id/Button9" android:text="9" android:gravity="center" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="0dip" android:layout_weight="1"/> </LinearLayout> </LinearLayout>
运行效果却很悲剧
上面一小部分始终显示不出来,中间那个View为什么那么不肯妥协,非要占据上面的位置。
这个问题困扰了我很长时间,问了很多人,有的说用RelativeLayout,但是我还是没有找到很好的解决方案
后来上网查资料发现LinearLayout的layout_weight属性是成反比的,跟空间的大小分配刚好是相反的
当时没太注意,后来百般无奈后,偶然间修改了那个View的layout的layout_weight
<LinearLayout android:id="@+id/puzzleview" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_weight="18"> </LinearLayout>
运行下一看,好像有点变化,通过LogCat观察出
每当我增大layout_weight时,onSizeChanged: width 35.5557:,height: 从45.33332逐渐减小到36.5557
慢慢的,上面犹抱琵琶半遮面的Chronometer空间终于露出来了
效果如图
通过这几天的Android编程,感觉编程有的时候真的很苦逼,你常常为了一个奇怪的问题,茶不思饭不想,水不喝了,厕所不上了,妹子不找了,就一心想着这个问题弄不出来就一直弄下去
但是当你解决问题时,那种感觉又是很美妙的,OK,编程还是要继续下去!!!
相关文章推荐
- [置顶] LinearLayout的layout_weight问题导致手机无法显示全部控件
- 【Android Studio】Android Monitor找不到手机问题-无法显示运行程序问题解决
- ionic3 解决img标签无法在手机上正常显示问题
- TocControl控件图层无法显示问题
- AutoLayout下多行UILabel无法显示多行文本的问题
- 源码解读android 5.0控件TabLayout无法自定义下划线宽度问题
- 部分手机无法显示Dialog问题
- AppbarLayout appbar_scrolling_view_behavior 导致的ContentFooter显示不全问题
- Android Process bar的自定义进度条 使用9 patch导致直接无法显示进度的问题
- 在RelativeLayout中对控件的显示隐藏操作问题
- Android手机ROOT之后更改字体文件导致无法启动的问题
- 在QMainWindow添加控件,无法显示问题
- VS中创建自定义控件后在ToolBox中无法显示的问题
- Android控件默认颜色与背景颜色相同导致显示问题
- 修改Material Design库的版本导致TabLayout无法使用的问题解决
- 解决Android Studio 无法显示Layout视图问题
- 梅花雨日历控件 修正DOCTYPE无法显示问题,增加清空按钮
- 关于scrollview 镶嵌linearlayout布局的控件位于底部的问题 关于scrollview镶嵌RelativeLayout布局失效
- 手机分辨率导致文字显示不完整的问题
- 微信开发:ToUserName、FromUserName写反导致手机上显示“该公众号暂时无法提供服务,请稍后再试”