排列方向

这段代码可以实现竖直排列。

    
ViewGroups_第1张图片 可以vertical

下面的代码运行没有问题,但是为什么没有竖直排列?

    
ViewGroups_第2张图片 没有vertical

将前一段代码的三行

    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:orientation="vertical" >~~~替换第二段代码的那三行,OK。![可以vertical了](http://upload-images.jianshu.io/upload_images/2994271-86d99e8c050e6972.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/240)差别是:android:orientation="vertical" >对的;android:layout_orientation = "vertical"错的当然排列方向可以横排horizental或者竖排vertical####高度宽度视图的高度、宽度都可以是固定的、wrap_content和match_parent试验如下代码:

android:layout_width = "wrap_content"android:layout_height = "wrap_content"android:orientation="vertical" >

android:text="Hi there!"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:textSize="36sp"
android:fontFamily="sans-serif-light"
android:textColor="@android:color/black"
android:background="#ccddff"
android:padding="20dp"/>

android:text="Hi there!"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="36sp"
android:fontFamily="sans-serif-light"
android:textColor="@android:color/black"
android:background="#ccddff"
android:padding="20dp"/>

android:text="Hi there!"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="36sp"
android:fontFamily="sans-serif-light"
android:textColor="@android:color/black"
android:background="#ccddff"
android:padding="20dp"/>
android:id="@+id/button1"
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#1cddff"
android:textSize="36sp"
android:text="Button 1" />

android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#1cddff"
android:textSize="36sp"
android:text="Button 2" />

android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="36sp"
android:background="#1cddff"
android:text="Button 3"/>

![好乱](http://upload-images.jianshu.io/upload_images/2994271-080ea32a08896330.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/480)如果想要均衡地将这些视图分布在device上,简单暴力地这样固定长度高度或者match_parent、wrap_content是行不通的。我们去搜索一下LinearLayout有没有办法实现均衡布局?let's Google search for a potential solution to the problem.![可以得到一大堆结果](http://upload-images.jianshu.io/upload_images/2994271-17d74fb8b9750c54.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/480)[这个网站](http://stackoverflow.com)在你需要其他人帮助时,可以查找问题答案,别人可能已经遇到了同样的问题,并且提出了答案。或者贴出问题,让别人来帮助你。网站手机打不开那也没办法!![Paste_Image.png](http://upload-images.jianshu.io/upload_images/2994271-a4582ff494d22634.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/480)提示我们可以使用layout_weight属性。

更多相关文章

  1. Android中拍照、图片、录音、视频和音频功能的方法和代码
  2. 【Android休眠】之Android对PowerKey事件的处理(1)代码流程
  3. android声音调整源代码分析
  4. Android 用代码获取基站号(cell)和小区号(lac)
  5. Android第一行代码(第二版)
  6. android手机通讯录备份还原代码
  7. 详解Android获取系统内核版本的方法与实现代码
  8. android典型代码系列(二十八)------通话记录的操作
  9. 【Android】Android清除本地数据缓存代码

随机推荐

  1. kotlin第一次运行在Android上
  2. Android 5.0使用android:onClick属性出现
  3. Android 按钮点击切换背景,同时修改文字颜
  4. Android下的图形处理
  5. NDK开发
  6. Android的RIL驱动模块启动流程
  7. 【Android 开发】:数据存储之 SQLite 数据
  8. 【Android】直接连接SqlServer
  9. Android中实现IPC的几种方式详细分析及比
  10. Android:Loading 动画——竜人の剣を喰え