麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 系統 > Android > 正文

android Activity線性布局和表格布局實例講解

2020-04-11 12:00:54
字體:
來源:轉載
供稿:網友

實驗中只需要編寫相應的xml的代碼,java代碼不需要更改,因為我們這里只是練習android的界面設計。

線性布局:
線性布局就是將各種控件按照行或者列依次進行排列。
其中本實驗用到的各控件的屬性解釋如下:
android:layout_weight屬性是指不同的控件在activity中占有體積大小的比例。
android:paddingLeft指內邊距左的距離,即控件內文字離控件左邊邊界的距離。其它的類推。
android:gravity指控件內文字相對于控件本身的方向屬性,長度為dip,與像素獨立的長度。
android:background為控件內文字顏色的背景色,顏色采用rgb時前面需用”#”號.
android:textSize為文本的大小,單位為pt,即鎊。
android:id為該控件的id,即在此處可以設置控件的id。
android:layout_width為控件本身的寬度屬性,其它的類似。
實驗結果顯示2行字,分別設置了不同的屬性。
效果如下:

xml代碼如下:

復制代碼 代碼如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <!--
        線性布局中
        android:layout_weight屬性是指不同的控件在activity中占有體積大小的比例。
        android:paddingLeft指內邊距左的距離,即控件內文字離控件左邊邊界的距離。其它的類推。
        android:gravity指控件內文字相對于控件本身的方向屬性,長度為dip,與像素獨立的長度。
        android:background為控件內文字顏色的背景色,顏色采用rgb時前面需用”#”號.
        android:textSize為文本的大小,單位為pt,即鎊。
        android:id為該控件的id,即在此處可以設置控件的id。
        android:layout_width為控件本身的寬度屬性,其它的類似。   
    -->

    <TextView
        android:id="@+id/London"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="倫敦奧運"
        android:textSize="20pt"
        android:background="#00ff00"
        android:gravity="center_horizontal"
        android:paddingLeft="10dip"
        android:paddingRight="10dip"
        android:paddingTop="10dip"
        android:paddingBottom="10dip"
        android:layout_weight="1"       
         />
    <TextView
        android:id="@+id/China"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="中國加油!!!"
        android:textSize="35pt"
        android:background="#ff0000"
        android:layout_weight="3"
         />

</LinearLayout>



表格布局:
表格布局有點類似表單的意思,可以在activity中建立多行,每一行又可以設置為多列,所以看起來橫豎條理比較清晰,因此叫做表格布局。
表格布局各控件屬性與線性布局類似,本實驗用到的屬性解釋如下:
用TableRow來增加一行,然后該行內各列依次并排。
android:padding指的是內邊距的4個方向都采用同樣的間距。
android:stretchColumns屬性表示當該行屬性設置為填充屏幕時,指定將哪一列拉伸。
實驗結果為顯示2行,每一行又有4列。
效果如下:

xml代碼如下:

復制代碼 代碼如下:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:stretchColumns="1"
    >
    <TableRow>
        <TextView
        android:text="國家"
        android:background="#848484"
        android:padding="2dip"
         />
        <TextView
            android:text="金牌"
            android:background="#ff0000"
            android:padding="2dip"
        />
        <TextView
            android:text="銀牌"
            android:background="#00ff00"
            android:padding="2dip"
            />
        <TextView
            android:text="銅牌"
            android:background="#0000ff"
            android:padding="2dip"
            />
        </TableRow>
    <TableRow >
         <TextView
        android:text="中國"
        android:background="#848484"
        android:padding="2dip"
         />
        <TextView
            android:text="*"
            android:background="#ff0000"
            android:padding="2dip"
        />
        <TextView
            android:text="**"
            android:background="#00ff00"
            android:padding="2dip"
            />
        <TextView
            android:text="***"
            android:background="#0000ff"
            android:padding="2dip"
            />
    </TableRow>
     <TableRow >
         <TextView
        android:text="美國"
        android:background="#848484"
        android:padding="2dip"
         />
        <TextView
            android:text="*"
            android:background="#ff0000"
            android:padding="2dip"
        />
        <TextView
            android:text="**"
            android:background="#00ff00"
            android:padding="2dip"
            />
        <TextView
            android:text="***"
            android:background="#0000ff"
            android:padding="2dip"
            />
    </TableRow>

</TableLayout>



 
線性布局和表格布局混合:
混合布局原理類似,只是大的layout中嵌入小layout,且小layout中又可以嵌入不同的layout。
這次實驗將上面的2個實驗混合起來顯示的,即總的布局為垂直方向上的線性布局,上面那個布局內部又為垂直方向的布局,下面那個布局為也是一個線性布局,不過里面嵌入了一個表格布局,所以總共有4個布局。
效果如下:

xml代碼如下:

復制代碼 代碼如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:layout_weight="1" >   
    <TextView
        android:id="@+id/London"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="倫敦奧運"
        android:textSize="5pt"
        android:background="#00ff00"
        android:gravity="center_horizontal"
        android:padding="10pt"
        android:layout_weight="1"       
         />
    <TextView
        android:id="@+id/China"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="中國加油!!!"
        android:textSize="8pt"
        android:background="#ff00ff"
        android:layout_weight="3"
         />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="3">
        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:stretchColumns="1"
            >
            <TableRow>
                <TextView
                android:text="國家"
                android:background="#848484"
                android:padding="2dip"
                 />
                <TextView
                    android:text="金牌"
                    android:background="#ff0000"
                    android:padding="2dip"
                />
                <TextView
                    android:text="銀牌"
                    android:background="#00ff00"
                    android:padding="2dip"
                    />
                <TextView
                    android:text="銅牌"
                    android:background="#0000ff"
                    android:padding="2dip"
                    />
                </TableRow>
            <TableRow >
                 <TextView
                android:text="中國"
                android:background="#848484"
                android:padding="2dip"
                 />
                <TextView
                    android:text="*"
                    android:background="#ff0000"
                    android:padding="2dip"
                />
                <TextView
                    android:text="**"
                    android:background="#00ff00"
                    android:padding="2dip"
                    />
                <TextView
                    android:text="***"
                    android:background="#0000ff"
                    android:padding="2dip"
                    />
            </TableRow>
             <TableRow >
                 <TextView
                android:text="美國"
                android:background="#848484"
                android:padding="2dip"
                 />
                <TextView
                    android:text="*"
                    android:background="#ff0000"
                    android:padding="2dip"
                />
                <TextView
                    android:text="**"
                    android:background="#00ff00"
                    android:padding="2dip"
                    />
                <TextView
                    android:text="***"
                    android:background="#0000ff"
                    android:padding="2dip"
                    />
            </TableRow>
        </TableLayout>
    </LinearLayout>

</LinearLayout>



實驗總結:
通過本次實驗對activity的簡單布局有了個初步的了解。

作者:tornadomeet

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 亚洲福利在线观看视频 | 国产高潮好爽好大受不了了 | 黄色片免费在线播放 | 日美av在线 | 精品国产一区二区三区免费 | 国产精品成人免费一区久久羞羞 | 久久不射电影 | 国产一区二区三区视频在线观看 | 一级毛片在线观看免费 | 天堂精品在线 | 欧美一级爱爱 | 在线观看一二三 | 九九色网站 | 操穴视频 | 久久精品a一级国产免视看成人 | 国产一国产一级毛片视频在线 | 欧美成人性生活片 | 视频一区二区三区在线观看 | 日韩精品久久久久久久九岛 | 国产a级片电影 | 国产xxxx岁13xxxxhd | 国产精品hd免费观看 | 久久草在线视频 | 国产乱色精品成人免费视频 | 一级看片免费视频 | 亚洲天堂在线电影 | 欧美精品黄色 | 狠狠操电影 | 法国极品成人h版 | 国产羞羞网站 | 久久久一区二区精品 | 亚洲影院在线 | 美女黄影院 | 国产日韩久久久久69影院 | 欧美 日韩 国产 在线 | 久久情爱网| 国产在线观看91精品 | 免费毛片小视频 | 欧美性猛交xxx乱大交3蜜桃 | 偿还电影免费看 | 美女久久|