Android-布局管理 (五大布局控件使用)

Android 之 四大组件、六大布局、五大存储 Android 之四大组件、六大布局、五大存储:https://blog.youkuaiyun.com/shenggaofei/article/details/52450668 Android 四大组件、五大存储、六大布局:https://blog.youkuaiyun.com/xiankog/article/details/81702119 Android四大基本组件介绍... 阅读详情

Android游戏开发-布局管理

2012/5/16 星期三 下午

  我们都知道,系统控件一般都会搭载进布局里的,在Android呢,提供了5种布局类型,通过这五种布局之间的相互组合可以构建各种复杂的布局。然而一个游戏当中,界面的布局是至关重要的一部分,一个漂亮的界面更能吸引玩家的眼球,并不是这个游戏的可玩性有多么的强,对于手机来说,无论是应用软件还是游戏,我认为手机里面的资源始终是有限的,不能什么样的游戏和软件都能移植到手机当中,然而一个好的界面能与用户得到很好的交互,那应该算是一个比较好的应用了。

  接下来,我还是继续学习Android游戏开发中的界面布局管理这一块,通过写博客来巩固自己学习到的东西,好记性不如烂笔头嘛。

  Layout(布局),上面提到Android提供了5种类型的布局类型,有哪5种呢?

  第一个:LinearLayout(线性布局)

  第二个:RelativeLayout(相对布局)

  第三个:TableLayout(表格布局)

  第四个:AbsoluteLayout(绝对布局)

  第五个:FrameLayout(单帧布局)

下面通过5个实例来学习这5种布局

创建项目分别为:

=>>Layout_01(线性布局)

=>>Layout_02(相对布局)

=>>Layout_03(表格布局)

=>>Layout_04(绝对布局)

=>>Layout_05(单帧布局)

那好,接下来精彩不断

@线性布局,是5种布局最常用的一种,从字面上也比较好理解,就是布局呈线性的,这种布局在显示组件的时候会默认保持组件之间的间隔以及组件之间的互相对齐。线性布局显示组件的方式有两种方式:垂直和水平,是通过orientation来设定的。

话先不多说,先建立一个项目:Layout_01

项目主要修改的是布局文件:main.xml

说明:这里只是为了展示布局的效果,控件的事件监听没有实现,所以只修改布局文件

运行项目效果:

=>>首先是垂直排列(vertical)

修改main.xml代码

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:orientation="vertical" >  
  6.   
  7.     <Button   
  8.         android:layout_width="fill_parent"  
  9.         android:layout_height="wrap_content"  
  10.         android:text="Button1"  
  11.         />  
  12.     <Button   
  13.         android:layout_width="fill_parent"  
  14.         android:layout_height="wrap_content"  
  15.         android:text="Button2"  
  16.         />  
  17.     <Button   
  18.         android:layout_width="fill_parent"  
  19.         android:layout_height="wrap_content"  
  20.         android:text="Button3"  
  21.         />  
  22.   
  23. </LinearLayout>  
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:orientation="vertical" >  
  6.   
  7.     <Button   
  8.         android:layout_width="fill_parent"  
  9.         android:layout_height="wrap_content"  
  10.         android:text="Button1"  
  11.         />  
  12.     <Button   
  13.         android:layout_width="fill_parent"  
  14.         android:layout_height="wrap_content"  
  15.         android:text="Button2"  
  16.         />  
  17.     <Button   
  18.         android:layout_width="fill_parent"  
  19.         android:layout_height="wrap_content"  
  20.         android:text="Button3"  
  21.         />  
  22.   
  23. </LinearLayout>  
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Button 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Button1"
        />
    <Button 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Button2"
        />
    <Button 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Button3"
        />

</LinearLayout>


=>>接着是水平排列(horizontal)

修改main.xml代码

说明:这里要修改每个按钮的填充形式,改为自适应内容的形式(wrap_content),不然只会看到button1,其他两个就因为超出屏幕导致无法看到。

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:orientation="horizontal" >  
  6.   
  7.     <Button   
  8.         android:layout_width="wrap_content"  
  9.         android:layout_height="wrap_content"  
  10.         android:text="Button1"  
  11.         />  
  12.     <Button   
  13.         android:layout_width="wrap_content"  
  14.         android:layout_height="wrap_content"  
  15.         android:text="Button2"  
  16.         />  
  17.     <Button   
  18.         android:layout_width="wrap_content"  
  19.         android:layout_height="wrap_content"  
  20.         android:text="Button3"  
  21.         />  
  22.   
  23. </LinearLayout>  
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:orientation="horizontal" >  
  6.   
  7.     <Button   
  8.         android:layout_width="wrap_content"  
  9.         android:layout_height="wrap_content"  
  10.         android:text="Button1"  
  11.         />  
  12.     <Button   
  13.         android:layout_width="wrap_content"  
  14.         android:layout_height="wrap_content"  
  15.         android:text="Button2"  
  16.         />  
  17.     <Button   
  18.         android:layout_width="wrap_content"  
  19.         android:layout_height="wrap_content"  
  20.         android:text="Button3"  
  21.         />  
  22.   
  23. </LinearLayout>  
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button1"
        />
    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button2"
        />
    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button3"
        />

</LinearLayout>

=>>在谈谈布局嵌套,这里是一个线性布局里头嵌套另一个线性布局

项目运行效果:


修改布局文件main.xml

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:orientation="horizontal" >  
  6.   
  7.     <Button   
  8.         android:layout_width="wrap_content"  
  9.         android:layout_height="wrap_content"  
  10.         android:text="Button1"  
  11.         />  
  12.     <LinearLayout   
  13.         android:orientation="vertical"  
  14.         android:layout_width="fill_parent"  
  15.         android:layout_height="fill_parent"  
  16.         >  
  17.         <Button   
  18.             android:layout_width="wrap_content"  
  19.             android:layout_height="wrap_content"  
  20.             android:text="Button2"  
  21.             />  
  22.         <Button   
  23.             android:layout_width="wrap_content"  
  24.             android:layout_height="wrap_content"  
  25.             android:text="Button3"  
  26.             />  
  27.           
  28.     </LinearLayout>  
  29. </LinearLayout>  
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:orientation="horizontal" >  
  6.   
  7.     <Button   
  8.         android:layout_width="wrap_content"  
  9.         android:layout_height="wrap_content"  
  10.         android:text="Button1"  
  11.         />  
  12.     <LinearLayout   
  13.         android:orientation="vertical"  
  14.         android:layout_width="fill_parent"  
  15.         android:layout_height="fill_parent"  
  16.         >  
  17.         <Button   
  18.             android:layout_width="wrap_content"  
  19.             android:layout_height="wrap_content"  
  20.             android:text="Button2"  
  21.             />  
  22.         <Button   
  23.             android:layout_width="wrap_content"  
  24.             android:layout_height="wrap_content"  
  25.             android:text="Button3"  
  26.             />  
  27.           
  28.     </LinearLayout>  
  29. </LinearLayout>  
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button1"
        />
   	<LinearLayout 
   	    android:orientation="vertical"
   	    android:layout_width="fill_parent"
   	    android:layout_height="fill_parent"
   	    >
   	    <Button 
        	android:layout_width="wrap_content"
        	android:layout_height="wrap_content"
        	android:text="Button2"
        	/>
    	<Button 
        	android:layout_width="wrap_content"
        	android:layout_height="wrap_content"
        	android:text="Button3"
        	/>
   	    
   	</LinearLayout>
</LinearLayout>

代码说明:这里button2和button3放在了嵌套的LinearLayout中,最外层的LinearLayout放置了button1,最外层的LinearLayout设置成水平方向horizontal,嵌套的LineaarLayout设置成垂直方向vertical。所以会看到Button1与Button2、Button3是以水平方向排列,Button2、Button3是以垂直方向排列。

下面总结线性布局里头一些常用的属性:

  android:id - 为控件指定相应的ID
  android:text - 指定控件当中显示的文字,需要注意的是,这里尽量使用string.xml
  android:gravity - 指定控件的基本位置,比如说居中,居右等位置
  android:textSize - 指定控件当中字体的大小
  android:background - 指定控件所用的背景色,RGB命名法
  android:layout_width - 指定控件的宽度
  android:layout_height - 指定控件的高度

  android:layout_weight - 指定控件的占用比例
  android:padding - 指定控件的内边距,也就是说控件当中的内容
  android:sigleLine - 如果设置为真的话,则将控件的内容显示在一行当中

下面继续在Layout_01项目修改main.xml来使用这些属性

项目运行效果:

修改main.xml代码:

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:orientation="vertical" >  
  6.     <!--  
  7.         android:id - 为控件指定相应的ID  
  8.         android:text - 指定控件当中显示的文字,需要注意的是,这里尽量使用string.xml  
  9.         android:gravity - 指定控件的基本位置,比如说居中,居右等位置  
  10.         android:textSize - 指定控件当中字体的大小  
  11.         android:background - 指定控件所用的背景色,RGB命名法  
  12.         android:width - 指定控件的宽度  
  13.         android:height - 指定控件的高度  
  14.         android:padding - 指定控件的内边距,也就是说控件当中的内容  
  15.         android:sigleLine - 如果设置为真的话,则将控件的内容显示在一行当中  
  16.         -->  
  17.   
  18.     <TextView  
  19.         android:id="@+id/firstText"  
  20.         android:text="第一行"  
  21.         android:gravity="center_vertical"  
  22.         android:textSize="15pt"  
  23.         android:background="#aa0000"  
  24.         android:layout_width="fill_parent"  
  25.         android:layout_height="wrap_content"  
  26.         android:paddingLeft="10dip"  
  27.         android:paddingTop="20dip"  
  28.         android:paddingRight="30dip"  
  29.         android:paddingBottom="40dip"  
  30.         android:layout_weight="2"  
  31.         android:singleLine="true"  
  32.         />  
  33.     <TextView   
  34.         android:id="@+id/secondText"  
  35.         android:text="第二行"  
  36.         android:gravity="center_vertical"  
  37.         android:textSize="15pt"  
  38.         android:background="#0000aa"  
  39.         android:layout_width="fill_parent"  
  40.         android:layout_height="wrap_content"  
  41.         android:layout_weight="1"  
  42.         />  
  43.           
  44. </LinearLayout>  
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:orientation="vertical" >  
  6.     <!--  
  7.         android:id - 为控件指定相应的ID  
  8.         android:text - 指定控件当中显示的文字,需要注意的是,这里尽量使用string.xml  
  9.         android:gravity - 指定控件的基本位置,比如说居中,居右等位置  
  10.         android:textSize - 指定控件当中字体的大小  
  11.         android:background - 指定控件所用的背景色,RGB命名法  
  12.         android:width - 指定控件的宽度  
  13.         android:height - 指定控件的高度  
  14.         android:padding - 指定控件的内边距,也就是说控件当中的内容  
  15.         android:sigleLine - 如果设置为真的话,则将控件的内容显示在一行当中  
  16.         -->  
  17.   
  18.     <TextView  
  19.         android:id="@+id/firstText"  
  20.         android:text="第一行"  
  21.         android:gravity="center_vertical"  
  22.         android:textSize="15pt"  
  23.         android:background="#aa0000"  
  24.         android:layout_width="fill_parent"  
  25.         android:layout_height="wrap_content"  
  26.         android:paddingLeft="10dip"  
  27.         android:paddingTop="20dip"  
  28.         android:paddingRight="30dip"  
  29.         android:paddingBottom="40dip"  
  30.         android:layout_weight="2"  
  31.         android:singleLine="true"  
  32.         />  
  33.     <TextView   
  34.         android:id="@+id/secondText"  
  35.         android:text="第二行"  
  36.         android:gravity="center_vertical"  
  37.         android:textSize="15pt"  
  38.         android:background="#0000aa"  
  39.         android:layout_width="fill_parent"  
  40.         android:layout_height="wrap_content"  
  41.         android:layout_weight="1"  
  42.         />  
  43.           
  44. </LinearLayout>  
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <!--
    	android:id - 为控件指定相应的ID
    	android:text - 指定控件当中显示的文字,需要注意的是,这里尽量使用string.xml
    	android:gravity - 指定控件的基本位置,比如说居中,居右等位置
    	android:textSize - 指定控件当中字体的大小
    	android:background - 指定控件所用的背景色,RGB命名法
    	android:width - 指定控件的宽度
    	android:height - 指定控件的高度
    	android:padding - 指定控件的内边距,也就是说控件当中的内容
    	android:sigleLine - 如果设置为真的话,则将控件的内容显示在一行当中
    	-->

 	<TextView
 	    android:id="@+id/firstText"
 	    android:text="第一行"
 	    android:gravity="center_vertical"
 	    android:textSize="15pt"
		android:background="#aa0000"
		android:layout_width="fill_parent"
		android:layout_height="wrap_content"
		android:paddingLeft="10dip"
		android:paddingTop="20dip"
		android:paddingRight="30dip"
		android:paddingBottom="40dip"
		android:layout_weight="2"
		android:singleLine="true"
		/>
 	<TextView 
 	    android:id="@+id/secondText"
 	    android:text="第二行"
 	    android:gravity="center_vertical"
 	    android:textSize="15pt"
 	    android:background="#0000aa"
 	    android:layout_width="fill_parent"
 	    android:layout_height="wrap_content"
 	    android:layout_weight="1"
 	    />
		
</LinearLayout>


再解释其中一些属性的作用:

=>>layout_weight,默认为零,其属性表示当前当前还有多大视图就占据多大视图;如果其值高于零,则表示将父视图中的可用的空间进行分割,分割的大小视当前屏幕整体布局的Layout_weight值与每个组件Layout_weight值占用比例来定。

=>>grivity:每个组件默认其值为左上角对齐,其属性可以调整组件对齐方式比如向左、向右或者居中对齐等。

=>>padding:边距的填充,也称内边距。其边距属性有:

   android:paddingTop,设置上边距

   android:paddingBottom,设置下边距

   android:paddingLeft,设置左边距

   android:paddingRight,设置右边距

   android:padding则表示周围四方向各内边距统一调整。

边距属性值为具体数字

=>>layout_margin,外边距,其上下左右属性为:

  android:layout_marginTop,设置上边距

  android:layout_marginBottom,设置下边距

  android:layout_marginLeft,设置左边距

  android:layout_marginRight,设置右边距

  android:layout_margin则表示设置四方向边距统一调整

这里说明一下padding与layout_margin的区别:

padding内边距指的是当前布局与包含的组件之间的边距

layout_margin外边距指的是与其他组件之间的边距。

呼呼,挺多内容的,接下来是RelativeLayout(相对布局)

RelativeLayout(相对布局)是除线性布局之外最常用的,它相对于线性布局来说比较灵活,在进行组件布局的时候用线性布局往往需要进行布局嵌套,而相对布局就不会那么麻烦,每个组件都可以指定与其它组件或父组件的位置,只是必须通过ID来进行指定。

创建项目:Layout_02(相对布局)

项目运行效果:

从项目运行结果可以看到:Button1在界面左上角,Button2在Button1下面,Button3在Button2下面并且对齐Button2右边缘,Button4在Button3下面并且对齐父组件右边缘对齐,Button5在Button4下面并且在水平方向的中央位置。

布局文件代码:

main.xml

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     >  
  6.   
  7.     <Button   
  8.         android:layout_width="wrap_content"  
  9.         android:layout_height="wrap_content"  
  10.         android:text="Button1"  
  11.         android:id="@+id/btn1"  
  12.         />  
  13.     <Button   
  14.         android:layout_width="fill_parent"  
  15.         android:layout_height="wrap_content"  
  16.         android:text="Button2"  
  17.         android:id="@+id/btn2"  
  18.         android:layout_below="@id/btn1"  
  19.         />  
  20.     <Button   
  21.         android:layout_width="wrap_content"  
  22.         android:layout_height="wrap_content"  
  23.         android:text="Button3"  
  24.         android:id="@+id/btn3"  
  25.         android:layout_below="@id/btn2"  
  26.         android:layout_alignRight="@id/btn2"  
  27.         />  
  28.     <Button  
  29.         android:layout_width="wrap_content"  
  30.         android:layout_height="wrap_content"  
  31.         android:text="Button4"  
  32.         android:id="@+id/btn4"  
  33.         android:layout_below="@id/btn3"  
  34.         android:layout_alignParentRight="true"  
  35.         />  
  36.     <Button  
  37.         android:layout_width="wrap_content"  
  38.         android:layout_height="wrap_content"  
  39.         android:text="Button5"  
  40.         android:id="@+id/btn5"  
  41.         android:layout_below="@id/btn4"  
  42.         android:layout_centerHorizontal="true"  
  43.         />  
  44.            
  45.  </RelativeLayout>  
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     >  
  6.   
  7.     <Button   
  8.         android:layout_width="wrap_content"  
  9.         android:layout_height="wrap_content"  
  10.         android:text="Button1"  
  11.         android:id="@+id/btn1"  
  12.         />  
  13.     <Button   
  14.         android:layout_width="fill_parent"  
  15.         android:layout_height="wrap_content"  
  16.         android:text="Button2"  
  17.         android:id="@+id/btn2"  
  18.         android:layout_below="@id/btn1"  
  19.         />  
  20.     <Button   
  21.         android:layout_width="wrap_content"  
  22.         android:layout_height="wrap_content"  
  23.         android:text="Button3"  
  24.         android:id="@+id/btn3"  
  25.         android:layout_below="@id/btn2"  
  26.         android:layout_alignRight="@id/btn2"  
  27.         />  
  28.     <Button  
  29.         android:layout_width="wrap_content"  
  30.         android:layout_height="wrap_content"  
  31.         android:text="Button4"  
  32.         android:id="@+id/btn4"  
  33.         android:layout_below="@id/btn3"  
  34.         android:layout_alignParentRight="true"  
  35.         />  
  36.     <Button  
  37.         android:layout_width="wrap_content"  
  38.         android:layout_height="wrap_content"  
  39.         android:text="Button5"  
  40.         android:id="@+id/btn5"  
  41.         android:layout_below="@id/btn4"  
  42.         android:layout_centerHorizontal="true"  
  43.         />  
  44.            
  45.  </RelativeLayout>  
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button1"
        android:id="@+id/btn1"
        />
    <Button 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Button2"
        android:id="@+id/btn2"
        android:layout_below="@id/btn1"
        />
    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button3"
        android:id="@+id/btn3"
        android:layout_below="@id/btn2"
        android:layout_alignRight="@id/btn2"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button4"
        android:id="@+id/btn4"
        android:layout_below="@id/btn3"
        android:layout_alignParentRight="true"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button5"
        android:id="@+id/btn5"
        android:layout_below="@id/btn4"
        android:layout_centerHorizontal="true"
        />
         
 </RelativeLayout>


知识补充:

 

表1-1 组件之间的位置关系
属性名称作用
android:layout_above将组件放在指定ID组件的上方
android:layout_below将组件放在指定ID组件的下方
android:layout_toLeftOf将组件放在指定ID组件的左方
android:layout_toRightOf将组件放在指定ID组件的右方

 

 

表1-2 组件对齐方式
属性名称作用
android:layout_alignBaseline将该组件放在指定ID组件进行中心线对齐
android:layout_alignTop将该组件放在指定ID组件进行顶部对齐
android:layout_alignBottom将该组件放在指定ID组件进行底部对齐

android:layout_alignLeft

将该组件放在指定ID组件进行左边缘对齐
android:layout_alignRight将该组件放在指定ID组件进行右边缘对齐

 

 

表1-3 当前组件与父组件的对齐方式
属性名称作用
android:layout_alignParentTop该组件与父组件进行顶部对齐
android:layout_alignParentBottom该组件与父组件进行底部对齐
android:layout_alignParentLeft该组件与父组件进行左边缘对齐
android:layout_alignParentRight该组件与父组件进行右边缘对齐

 

 

表1-4 组件放置的位置
属性名称作用
android:layout_centerHorizontal将该组件放置在水平方向中央的位置
android:layout_centerVertical将该组件放置在垂直方向的中央的位置
anroid:layout_centerInParent将该组件放置在父组件的水平中央及垂直中央的位置

 

第3 part-TableLayout(表格布局)

TableLayout(表格布局),顾名思义就是像表格一样布局,通常情况下,TableLayout有多个TableRow组成,每个TableRow就是一行,定义几个TableRow就是定义几行;

创建项目:Layout_03(表格布局)

项目运行效果:

修改布局文件:

main.xml

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     >  
  6.     <TableRow>  
  7.         <Button android:text="Button1"/>  
  8.         <Button android:text="Button2"/>  
  9.         <Button android:text="Button3"/>  
  10.     </TableRow>  
  11.     <TableRow>  
  12.         <Button android:text="Button4"/>  
  13.         <Button android:text="Button5"/>  
  14.         <Button android:text="Button6"/>  
  15.     </TableRow>  
  16.     <TableRow>  
  17.         <Button android:text="Button7"/>  
  18.         <Button android:text="Button8"/>  
  19.         <Button android:text="Button9"/>  
  20.     </TableRow>  
  21. </TableLayout>  
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     >  
  6.     <TableRow>  
  7.         <Button android:text="Button1"/>  
  8.         <Button android:text="Button2"/>  
  9.         <Button android:text="Button3"/>  
  10.     </TableRow>  
  11.     <TableRow>  
  12.         <Button android:text="Button4"/>  
  13.         <Button android:text="Button5"/>  
  14.         <Button android:text="Button6"/>  
  15.     </TableRow>  
  16.     <TableRow>  
  17.         <Button android:text="Button7"/>  
  18.         <Button android:text="Button8"/>  
  19.         <Button android:text="Button9"/>  
  20.     </TableRow>  
  21. </TableLayout>  
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <TableRow>
        <Button android:text="Button1"/>
        <Button android:text="Button2"/>
        <Button android:text="Button3"/>
    </TableRow>
    <TableRow>
        <Button android:text="Button4"/>
        <Button android:text="Button5"/>
        <Button android:text="Button6"/>
    </TableRow>
    <TableRow>
        <Button android:text="Button7"/>
        <Button android:text="Button8"/>
        <Button android:text="Button9"/>
    </TableRow>
</TableLayout>


TableLayout就那么简单,TableLayout中也有几个常用属性:

(1)shrinkColumns属性:以0为序,当TableRow里面的控件布满布局时,,指定列自动延伸以填充可用部分;当TableRow里面的控件还没有布满布局时,shrinkColumns不起作用。

在布局文件中添加shrinkColumns属性代码:

  1. <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     android:layout_width="fill_parent"  
  3.     android:layout_height="fill_parent"  
  4.     android:shrinkColumns="2">  
  1. <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     android:layout_width="fill_parent"  
  3.     android:layout_height="fill_parent"  
  4.     android:shrinkColumns="2">  
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:shrinkColumns="2">

指定第3列填充可用部分,运行项目效果如图:

没有发生变化,因为TableRow里面的控件还没有布满布局,现在再修改布局文件如下:

现在可以看到,shinkColumns属性起作用了。

  1.   
  2.   
  3. <TableRow>  
  4.       <Button android:text="Button1"/>  
  5.       <Button android:text="Button2"/>  
  6.       <Button android:text="Button3333333333333333333333333"/>  
  7.   </TableRow>  
  1.   
  2.   
  3. <TableRow>  
  4.       <Button android:text="Button1"/>  
  5.       <Button android:text="Button2"/>  
  6.       <Button android:text="Button3333333333333333333333333"/>  
  7.   </TableRow>  
  

  <TableRow>
        <Button android:text="Button1"/>
        <Button android:text="Button2"/>
        <Button android:text="Button3333333333333333333333333"/>
    </TableRow>

(2)strechColumns属性,以第0行为序,指定列对空白部分进行填充。

在布局中添加strechColumns属性代码如下:

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:stretchColumns="2">  
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:stretchColumns="2">  
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="2">


android:strechColumns:指定第3列填充空白部分

(3)collapseColumns属性:以0行为序,隐藏指定的列

在布局中添加collapseColumns属性代码如下:

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:collapseColumns="2">  
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:collapseColumns="2">  
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:collapseColumns="2">


运行效果如图:

android:collapseColumns="2":指定第3列隐藏

(4)layout_column属性:以0行为序,设置组件显示指定列

(5)layout_span属性:以第0行为序,设置组件显示占用的列数。

修改布局代码如下:

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent">  
  5.     <TableRow>  
  6.         <Button android:text="Button1"  
  7.             android:layout_span="3"/>  
  8.         <Button android:text="Button2"/>  
  9.         <Button android:text="Button3"/>  
  10.     </TableRow>  
  11.     <TableRow>  
  12.         <Button android:text="Button4"  
  13.             android:layout_column="2"/>  
  14.         <Button android:text="Button5"  
  15.             android:layout_column="0"/>  
  16.         <Button android:text="Button6"/>  
  17.     </TableRow>  
  18.     <TableRow>  
  19.         <Button android:text="Button7"/>  
  20.         <Button android:text="Button8"/>  
  21.         <Button android:text="Button9"/>  
  22.     </TableRow>  
  23. </TableLayout>  
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent">  
  5.     <TableRow>  
  6.         <Button android:text="Button1"  
  7.             android:layout_span="3"/>  
  8.         <Button android:text="Button2"/>  
  9.         <Button android:text="Button3"/>  
  10.     </TableRow>  
  11.     <TableRow>  
  12.         <Button android:text="Button4"  
  13.             android:layout_column="2"/>  
  14.         <Button android:text="Button5"  
  15.             android:layout_column="0"/>  
  16.         <Button android:text="Button6"/>  
  17.     </TableRow>  
  18.     <TableRow>  
  19.         <Button android:text="Button7"/>  
  20.         <Button android:text="Button8"/>  
  21.         <Button android:text="Button9"/>  
  22.     </TableRow>  
  23. </TableLayout>  
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TableRow>
        <Button android:text="Button1"
            android:layout_span="3"/>
        <Button android:text="Button2"/>
        <Button android:text="Button3"/>
    </TableRow>
    <TableRow>
        <Button android:text="Button4"
            android:layout_column="2"/>
        <Button android:text="Button5"
            android:layout_column="0"/>
        <Button android:text="Button6"/>
    </TableRow>
    <TableRow>
        <Button android:text="Button7"/>
        <Button android:text="Button8"/>
        <Button android:text="Button9"/>
    </TableRow>
</TableLayout>


运行效果:

从效果图可知:Button1被设置了占用了3列,Button4被设置显示在地3列,但代码指定Button5显示在第一列,但没有按照设定显示,这样可知TableRow在表格布局中,一行里的组件都会自动放在前一组件的右侧,依次排列,只要确定了所在列,其后面的组件就无法在进行设置位置。

第4 part AbsoluteLayout(绝对布局)

AbsoluteLayout(绝对布局)布局用法如其名,组件的位置可以准确的指定其在屏幕的x/y坐标位置。虽然可以精确的去规定坐标,但是由于代码的书写过于刚硬,使得在不同的设备,不同分辨率的手机移动设备上不能很好的显示应有的效果,所以此布局不怎么被推荐使用。

创建项目:Layout_04(绝对布局)

修改布局文件代码如下:

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6.     >  
  7.     <Button   
  8.         android:layout_width="wrap_content"  
  9.         android:layout_height="fill_parent"  
  10.         android:text="Button1"  
  11.         android:layout_x="100dp"  
  12.         />  
  13.     <Button   
  14.         android:layout_width="fill_parent"  
  15.         android:layout_height="wrap_content"  
  16.         android:text="Button2"  
  17.         android:layout_y="100dp"  
  18.         />  
  19.       
  20.     </AbsoluteLayout>  
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6.     >  
  7.     <Button   
  8.         android:layout_width="wrap_content"  
  9.         android:layout_height="fill_parent"  
  10.         android:text="Button1"  
  11.         android:layout_x="100dp"  
  12.         />  
  13.     <Button   
  14.         android:layout_width="fill_parent"  
  15.         android:layout_height="wrap_content"  
  16.         android:text="Button2"  
  17.         android:layout_y="100dp"  
  18.         />  
  19.       
  20.     </AbsoluteLayout>  
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <Button 
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="Button1"
        android:layout_x="100dp"
        />
    <Button 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Button2"
        android:layout_y="100dp"
        />
    
    </AbsoluteLayout>


项目运行效果:

运行效果说明:Button1的x坐标设定为了100像素,Button2的y坐标设定为了100像素。

第5 part FrameLayout(单帧布局)

FrameLayout(单帧布局),据说是五种布局中最简单的一种,因为单帧布局在新定义组件的时候都会将组件放置屏幕的左上角,即使在此布局中定义多个组件,后一个组件总会将前一个组件所覆盖,除非最后一个组件是透明的。

创建项目:Layout_05

修改布局文件代码如下:

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     >  
  6.     <Button   
  7.         android:layout_width="fill_parent"  
  8.         android:layout_height="wrap_content"  
  9.         android:text="Button1"  
  10.         />  
  11.     <Button   
  12.         android:layout_width="wrap_content"  
  13.         android:layout_height="fill_parent"  
  14.         android:text="Button2"  
  15.         />  
  16.     <Button   
  17.         android:layout_width="wrap_content"  
  18.         android:layout_height="wrap_content"  
  19.         android:text="Button3"  
  20.         />  
  21.       
  22. </FrameLayout>  
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     >  
  6.     <Button   
  7.         android:layout_width="fill_parent"  
  8.         android:layout_height="wrap_content"  
  9.         android:text="Button1"  
  10.         />  
  11.     <Button   
  12.         android:layout_width="wrap_content"  
  13.         android:layout_height="fill_parent"  
  14.         android:text="Button2"  
  15.         />  
  16.     <Button   
  17.         android:layout_width="wrap_content"  
  18.         android:layout_height="wrap_content"  
  19.         android:text="Button3"  
  20.         />  
  21.       
  22. </FrameLayout>  
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <Button 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Button1"
        />
    <Button 
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="Button2"
        />
    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button3"
        />
    
</FrameLayout>

项目运行效果:


效果图说明:可以看到3个按钮组件都有重叠的部分,单帧布局不会像线性布局那样每个组件之间自动对齐且组件之间都有间隙

安卓五大布局详解 文章目录通用属性RelativeLayout 相对布局LinearLayout 线性布局TableLayout 表格布局FrameLayout帧布局ConstraintLayout 约束布局 1 添加目录只需要在博客最前边添加 在安卓中为了适应不同的界面风格,系统提供了五种布局分别是:线性布局 LinearLayout,帧布局 FrameLayout,相对布局 RelativeLayout,表格布局 TableLayout和约束布局 ConstrainLayout。 通用属性 这几个布局拥有通用的属性 阅读详情

相关推荐

从实习生到独立上手:我是如何用海思PQTool搞定IPC图像调试的

本文分享了从实习生到独立使用海思PQTool进行IPC图像调试的成长历程。通过工具搭建、核心参数调整和实战案例,详细介绍了如何高效解决图像质量问题,特别强调了ISP调试中的关键参数和实用技巧,适合刚入门的图像调试工程师参考。

weixin_33756596的博客 312

Android游戏开发-布局管理

Android游戏开发-布局管理 2012/5/16 星期三 下午 我们都知道,系统控件一般都会搭载进布局里的,在Android呢,提供了5种布局类型,通过这五种布局之间的相互组合可以构建各种复杂的布局。然而一个游戏当中,界面的布局是至关重要的一部分,一个漂亮的界面更能吸引玩家的眼球,并不是这个游戏的可玩性有多么的强,对于手机来说,无论是应用软件还是游戏,我认为手机里面的资源始终...

mmdev 402

WSL2+Ubuntu20.04纯root环境搭建指南:告别权限烦恼的终极方案

本文提供了一份详细的WSL2+Ubuntu20.04纯root环境搭建指南,旨在为本地开发与学习打造一个免去权限干扰、极致流畅的Linux子系统环境。通过启用WSL2、安装Ubuntu 20.04,并执行核心的root用户设置,开发者可以彻底告别频繁的sudo操作,提升在文件操作、容器调试和系统配置等方面的效率。

time3的博客 474

android 按钮并排左右_用户界面-并排2个按钮-android布局

用户界面-并排2个按钮-android布局我如何才能将2个按钮并排放置,以使它们占据整个宽度,并且它们之间有一点间距。我想过一个水平线性布局,其中2个子线性布局设置为与父级和权重1匹配,每个线性布局都包含按钮..有没有更简单的方法? 可以通过相对布局完成吗?谢谢!4个解决方案104 votesandroid:id="@+id/LinearLayout02"android:layout_height...

weixin_39594439的博客 3079

西门子200SMART自定义库开发实战:从PID到露点算法的工业应用

本文详细介绍了西门子200SMART自定义库开发实战,涵盖从PID控制到露点算法的工业应用。通过代码封装技巧、多语言支持和性能优化等高级开发方法,帮助工程师提升PLC编程效率。文章特别强调了自创库在实际项目中的优势,如恒温恒湿控制系统的成功案例,展示了自定义库在工业自动化中的强大应用价值。

lake5的博客 1028

从轴承润滑到代码实现:手把手教你用Python FDM求解稳态雷诺方程

本文详细介绍了如何用Python FDM(有限差分法)求解稳态雷诺方程,从轴承润滑理论到代码实现的全过程。通过构建无量纲方程、有限差分格式和迭代求解算法,开发者可以快速实现专业级润滑分析,应用于涡轮发电机、汽车曲轴等场景。文章还提供了完整的Python代码示例和结果可视化方法,帮助工程师优化轴承设计。

weixin_28689507的博客 120

将android 中radiobutton设置为并排分布

其他相似的组件也都是同样的用法

weixin_52369679的博客 778

cadence数模混合仿真反标sdf

数模混合IC设计时经常要调用一些Verilog模块(最简单的例如SPI接口),在前仿时一般直接用rtl代码来仿真,但是后仿时要关注因寄生带来的延迟,避免这些额外的延迟导致时序错误,因此不能简单地采用RTL来仿真。 一般有两种办法:1是采用由RTL综合得到的门级电路来仿真,这种方法比较简单,但是缺点是规模较大,而且只包括门延迟不包括因版图导致的线延迟;如果想要仿真更精细,就要对该这部分门电路提取寄生参数; 另一种方式是利用sdf文件(standard delay format)来进行仿真。后端工具在布局布

长河柱天的博客 7275

android并排放按钮,如何在Android中将两个按钮放在同一行

只需做一个线性的布局.将方向设置为水平,并添加两个按钮.它准备好你会得到你想要的.在发布这样的问题之前,尝试谷歌搜索,你会得到答案肯定.这段代码将帮助你.android:layout_width="match_parent"android:layout_height="wrap_content" >android:id="@+id/button1"android:layout_width="...

weixin_39961522的博客 7465

MySQL服务启动失败?手把手教你排查NET HELPMSG 3534错误(附完整修复流程)

本文针对Windows平台上MySQL服务启动失败并提示NET HELPMSG 3534错误的常见问题,提供了系统性的排查与修复指南。文章深入剖析了错误本质,并手把手教你通过查看MySQL错误日志、检查并初始化数据目录、修正Windows服务配置、排查my.ini配置文件陷阱等核心步骤,彻底解决这一棘手问题,帮助开发者和运维人员快速恢复数据库服务。

wdx0123456的博客 895

【unity实战】Unity手搓脚本工具实现合并网格功能

本文介绍了在Unity中优化网格性能的方法,通过合并重复网格减少绘制调用。主要使用Mesh.CombineMeshes方法实现网格合并,支持统一材质和多材质处理。核心内容包括:1)基础合并脚本实现,将子网格合并到父对象并禁用原网格;2)统一材质设置,支持自定义或默认材质;3)多材质合并方案,通过设置mergeSubMeshes=false保留子网格材质索引。文章还提供了完整代码示例和操作演示,适用于实际项目中的网格优化需求。

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 560

android 按钮并排左右_线性布局有两个按钮并排 - 安卓

我有3个按钮下出现低于对方的,其中layout.xml ...线性布局有两个按钮并排 - 安卓android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"android:padding="10dip" >android:layout_width="fi...

weixin_32431067的博客 2810

利用恒源云云端GPU高效训练YOLOv11模型全流程:从环境搭建到模型部署,让你摆脱硬件束缚

记住,云端GPU的核心优势是“弹性算力+一键环境”,只要把握好这一工具特性,再结合YOLOv11的高性能模型架构,你也能在计算机视觉领域快速落地项目。接下来,我们从工具准备到模型部署,一步步带你实现高效训练,真正帮你解决资源与效率的核心痛点。凭借其在目标检测、实例分割任务上的卓越性能,成为众多开发者的首选。据统计,使用云端GPU训练YOLOv11,在处理百万级数据集时,训练效率较本地普通GPU提升。在安防监控中,YOLOv11可实时检测人员、车辆异常行为,某园区采用该方案后,异常事件识别准确率达。

LXY_LOVE36的博客 213

理解android中的activity,intent和bundle,以及五大布局,主题和样式, UI控件

intent可简单理解为意图,跳转到哪里 bundle可理解为key-》value的类,类似Map activity有七个生命周期。   AndroidManifest.xml是android程序入口   http://blog.youkuaiyun.com/randyjiawenjie/article/details/6651437   五大布局:五大布局分别是LinearLayout(...

iteye_2629的博客 153

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

android button 添加事件_Android布局详解,附代码

有哪些布局类型?Android系统中为我们提供的五大布局:LinearLayout(线性布局)、FrameLayout(单帧布局)、AbsoluteLayout(绝对布局)、TablelLayout(表格布局)、RelativeLayout(相对布局)。其中最常用的的是LinearLayout、TablelLayout和RelativeLayout。这些布局都可以嵌套使用。LinearLayout...

weixin_39923623的博客 220

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

Android快速入门教程总结帖,2021年阿里Android面试题及答案

授课方式:ppt&源码&讲解 课程难度:入门级 课程目录:http://blog.youkuaiyun.com/wwj_748/article/details/44892627 所有课程源码和ppt已公开:http://pan.baidu.com/s/1bnm7kAz 小巫从最基本的开发工具介绍开始给大家介绍了关于Android开发中需要用到的一些开发工具,比如IDE、SDK里面的一些工具;接着讲了如何去搭建开发环境,这里涉及到Java环境变量的配置、SDK环境变量的配置,我们要知道的时Eclipse需

m0_66264134的博客 180

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

Android应用界面开发(二)

Android 里布局的一些事情。

菜鸟要飞翔 832

Android快速入门教程总结帖

授课方式:ppt&源码&讲解 课程难度:入门级 课程目录:[http://blog.youkuaiyun.com/wwj_748/article/details/44892627](() 所有课程源码和ppt已公开:[http://pan.baidu.com/s/1bnm7kAz](() 小巫从最基本的开发工具介绍开始给大家介绍了关于Android开发中需要用到的一些开发工具,比如IDE、SDK里面的一些工具;接着讲了如何去搭建开发环境,这里涉及到Java环境变量的配置、SDK环境变量的配置,我们要知道

m0_66640396的博客 162

安卓五大布局

Android中常用的5大布局方式有以下几种: 线性布局(LinearLayout):顾名思义就是按照垂直或者水平方向布局的组件。帧布局(FrameLayout):组件从屏幕左上方布局组件,就像CSS中的多个盒子重叠在一起,组件有层次区分。表格布局(TableLayout):按照行列方式布局组件,组件被包裹在表格中。相对布局(RelativeLayout):相对其它组件的布局方式。 绝对布局

Gpwner的博客 1082

Android系统五大布局详解Layout

我们知道Android系统应用程序一般是由多个Activity组成,而这些Activity以视图的形式展现在我们面前,视图都是由一个一个的组件构成的。组件就是我们常见的Button、TextEdit等等。那么我们平时看到的Android手机中那些漂亮的界面是怎么显示出来的呢?这就要用到Android的布局管理器了,网上有人比喻的很好:布局好比是建筑里的框架,组件按照布局的要求依次排列,就组成了用于

漫步云端 5万+

Android约束布局ConstraintLayout的使用

Android约束布局ConstraintLayout的基本使用 约束布局ConstraintLayout面世已有很长一段时间了,但我一直没有关注这个Android 中继五大布局后的新布局的使用。近日在网友的讨论的强烈推荐下,尝试了ConstraintLayout。使用之后的最大感触就是:为什么我不早点在项目中尝试ConstraintLayout!!! 本篇文章,旨在记录ConstraintLay...

qq_36046305的博客 2万+
上一篇: 恢复linux下误删除的文件
下一篇: 微信5.0服务号运营三部曲
cctcc
博客等级 码龄23年 104粉丝 63原创
评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值