国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

android Activity相對布局的使用方法

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

相對布局要比前面講的線性布局和表格布局要靈活一些,所以平常用得也是比較多的。相對布局控件的位置是與其周圍控件的位置相關的,從名字可以看出來,這些位置都是相對的,確定出了其中一個控件的位置就可以確定另一個控件的位置了。
本次實驗就是顯示如下的activity:


    
其中只有2個button,1個textview,1個edittext。

在相對布局中,一般用到的控件屬性解釋如下:
在相對布局中有如下屬性,解釋如下:
android:layout_above  為將該控件的底部放在指定id控件的上方
android:layout_below   同理類似,將該控件的頂部放在指定id控件的下方
android:layout_toLeftOf  將該控件的右端緊挨著放在指定id控件的左端。
android:layout_toRightOf  將該控件的左端緊挨著放在指定id控件的右端
android:layout_alignParentRight  為true時將該控件右端與父控件右端對齊
android:layout_alignParentLeft       為true時將該控件左端與父控件左端對齊
android:layout_alignParentTop       為true時將該控件頂端與父控件頂端對齊
android:layout_alignParentBottom  為true時將該控件底端與父控件底端對齊
android:layout_alignBottom   將該控件底部與指定id控件底部控件對齊
android:layout_alignLeft 將該控件左邊與指定id控件左邊對齊
android:layout_alignRight        將該控件右邊與指定id控件右邊對齊
android:layout_alignTop  將該控件頂端與指定id控件頂端對齊

實現上面activity比較簡單,其xml代碼如下:

復制代碼 代碼如下:

<RelativeLayout 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:padding="10px" >

    <TextView
        android:id="@+id/input"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/input_dis"
        tools:context=".MainActivity" />

       <EditText
  android:id="@+id/edit"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
        android:layout_below="@id/input"
        android:background="@android:drawable/editbox_background"
        />

       <Button
  android:id="@+id/ok"
  android:layout_height="wrap_content"
  android:layout_width="wrap_content"
  android:layout_below="@id/edit"
  android:layout_alignParentRight="true"
  android:layout_marginLeft="10px"
  android:text="@string/ok" 
  />

       <Button
  android:id="@+id/cancel"
  android:layout_height="wrap_content"
  android:layout_width="wrap_content"
  android:layout_below="@id/edit"
  android:layout_toLeftOf="@id/ok"
  android:text="@string/cancel"

  />

</RelativeLayout>



 總結:activity的相對布局比較靈活,一些常見的屬性也比較多,用得多自然就會了。

 
 作者:tornadomeet

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 五峰| 斗六市| 呼和浩特市| 大方县| 九寨沟县| 民和| 赤壁市| 安义县| 客服| 太仓市| 巩留县| 武冈市| 建昌县| 江陵县| 江口县| 巧家县| 白水县| 泾川县| 黎平县| 宜春市| 辽中县| 平泉县| 诸城市| 乡宁县| 凤翔县| 宁安市| 融水| 怀宁县| 神木县| 康平县| 石林| 虎林市| 米脂县| 廉江市| 会昌县| 营口市| 柘荣县| 潞西市| 枣庄市| 北碚区| 获嘉县|