Mono for Android (1) 之布局

来源:互联网 发布:知乎dota2与lol 编辑:程序博客网 时间:2024/05/18 22:08
最近和同事交接工作,首次接触mono for android, 结果画view时少了layout,页面没办法出来,各种冥思,各种找问题,最后把关于布局的一些共享出来(同事写的,哈哈):
 
Android RelativeLayout 属性

// 相对于给定ID控件

android:layout_above 将该控件的底部置于给定ID的控件之上;

android:layout_below 将该控件的底部置于给定ID的控件之下;

android:layout_toLeftOf    将该控件的右边缘与给定ID的控件左边缘对齐;

android:layout_toRightOf  将该控件的左边缘与给定ID的控件右边缘对齐;

 

android:layout_alignBaseline  将该控件的baseline与给定ID的baseline对齐;

android:layout_alignTop        将该控件的顶部边缘与给定ID的顶部边缘对齐;

android:layout_alignBottom   将该控件的底部边缘与给定ID的底部边缘对齐;

android:layout_alignLeft        将该控件的左边缘与给定ID的左边缘对齐;

android:layout_alignRight      将该控件的右边缘与给定ID的右边缘对齐;

// 相对于父组件

android:layout_alignParentTop      如果为true,将该控件的顶部与其父控件的顶部对齐;

android:layout_alignParentBottom 如果为true,将该控件的底部与其父控件的底部对齐;

android:layout_alignParentLeft      如果为true,将该控件的左部与其父控件的左部对齐;

android:layout_alignParentRight    如果为true,将该控件的右部与其父控件的右部对齐;

// 居中

android:layout_centerHorizontal 如果为true,将该控件的置于水平居中;

android:layout_centerVertical     如果为true,将该控件的置于垂直居中;

android:layout_centerInParent   如果为true,将该控件的置于父控件的中央;

// 指定移动像素

android:layout_marginTop      上偏移的值;

android:layout_marginBottom 下偏移的值;

android:layout_marginLeft 左偏移的值;

android:layout_marginRight 右偏移的值;

 

example:

android:layout_below = "@id/***"

android:layout_alignBaseline = "@id/***"

android:layout_alignParentTop = true

android:layout_marginLeft = “10px”


1、 TableLayout 通过添加 TableRow 控制行数,通过一行中的组件个数来控制列数。 
      表格布局中列的宽度即是每一列中最宽的组件的宽度。
2、 表格布局中, 全局属性也即列属性   三种属性:
AXML属性 相关方法 说明 android:collapseColumns setColumnCollapsed(int,boolean) 设置需要隐藏的列的序号,多个之间用逗号分隔 Android:shrinkColumns setShrinkAllColumns(boolean) 设置允许被收缩的列的序号,多个之间用逗号分隔 Android:stretchColumns setStretchAllColumns(boolean) 设置允许被拉伸的列的序号,多个之间用逗号分隔
 
        单元格属性:
   android:layout_column    指定该单元格在第几列显示
   android:layout_span      指定该单元格占据的列数(未指定时,为1)
 
3、如果多行之间的格式不一致时,可以通过嵌套的形式定义新的格式。
                      <TableRow>
                    <EditText
                        android:id="@+id/TaskTypeTxt"
                        android:padding="3dip"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1" />
                    <ImageView
                        android:id="@+id/TaskTypeTxtImg"
                        android:src="@drawable/HistoryRecord"
                        android:layout_height="30dip"
                        android:layout_width="30dip" />
                </TableRow>
                <View
                    android:layout_height="2dip"
                    android:background="#E3E3E3" />
                <TableRow>
                    <EditText
                        android:id="@+id/EnterpriseNameTxt"
                        android:padding="3dip"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1" />
                    <ImageView
                        android:id="@+id/EnterpriseNameImg"
                        android:src="@drawable/HistoryRecord"
                        android:layout_height="30dip"
                        android:layout_width="30dip" />
                </TableRow>
          TableRow 与 TableRow 之间可以通过  画一个View(分割线) 来分割。
    通过设置控件的 android:layout_weight="1" ,防止控件的值太长时,将其他控件挤出屏幕。
     

<script type="text/javascript"><!--google_ad_client = "ca-pub-1944176156128447";/* cnblogs 首页横幅 */google_ad_slot = "5419468456";google_ad_width = 728;google_ad_height = 90;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>