最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android開發(fā)中include控件用法分析

 更新時間:2016年10月24日 10:12:12   作者:pku_android  
這篇文章主要介紹了Android開發(fā)中include控件用法,結合實例形式分析了Android界面布局中include控件的使用技巧,需要的朋友可以參考下

本文實例講述了Android開發(fā)中include控件用法。分享給大家供大家參考,具體如下:

我們知道,基于Android系統(tǒng)的應用程序的開發(fā),界面設計是非常重要的,它關系著用戶體驗的好壞。一個好的界面設計,不是用一個xml布局就可以搞定的。當一個activity中的控件非常多的時候,所有的布局文件都放在一個xml文件中,很容易想象那是多么糟糕的事情!筆者通過自身的經歷,用include控件來解決這個問題,下面是一個小例子,僅僅實現(xiàn)的是布局,沒有響應代碼的設計。

user.xml文件內容如下:

<?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" >
  <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="用戶名: " />
  <EditText
    android:layout_width="150dp"
    android:layout_height="wrap_content"
    android:id="@+id/userName"
    android:hint="請輸入用戶名"
    />
</LinearLayout>

passwd.xml文件內容如下:

<?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" >
   <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="密   碼:" />
  <EditText
    android:layout_width="150dp"
    android:layout_height="wrap_content"
    android:id="@+id/passWd"
    android:hint="請輸入密碼"
    />
</LinearLayout>

login.xml文件內容如下:

<?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"
  android:orientation="horizontal" >
  <Button
    android:layout_width="80dp"
    android:layout_height="wrap_content"
    android:id="@+id/bt"
    android:hint="確定"
    />
  <Button
    android:layout_width="80dp"
    android:layout_height="wrap_content"
    android:id="@+id/reset"
    android:layout_toRightOf="@id/bt"
    android:hint="重置"
    />
</RelativeLayout>

main.xml文件內容如下:

<?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:layout_alignParentBottom="true">
<RelativeLayout
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
  android:layout_alignParentBottom="true">
 <LinearLayout
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:id="@+id/head"
  android:layout_alignParentTop="true">
   <include
   android:layout_width="fill_parent"
   layout="@layout/user">
   </include>
 </LinearLayout>
 <LinearLayout
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:id="@+id/middle"
  android:layout_below="@id/head"
  android:layout_alignParentLeft="true">
   <include
   android:layout_width="fill_parent"
   layout="@layout/passwd">
   </include>
  </LinearLayout>
  <LinearLayout
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:id="@+id/foot"
  android:layout_below="@id/middle"
  android:layout_alignParentRight="true">
   <include
   android:layout_width="fill_parent"
   layout="@layout/login">
   </include>
   </LinearLayout>
</RelativeLayout>
</LinearLayout>

程序運行結果如下:

如果在main.xml中這樣寫:

<?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:layout_alignParentBottom="true">
   <include
   android:layout_width="fill_parent"
   layout="@layout/user">
   </include>
   <include
   android:layout_width="fill_parent"
   layout="@layout/passwd">
   </include>
   <include
   android:layout_width="fill_parent"
   layout="@layout/login">
   </include>
</LinearLayout>

那么該情況下的運行結果如下:

很顯然運行結果與預期不符,接下來的四個控件出不來,為什么呢?(想必大家在做實驗的時候,肯定遇到過這個問題?。?/p>

其實關鍵的地方是main文件中對各個xml的布局,沒有相應的布局,結果是非常慘的,大家可以根據(jù)我的代碼在修改下相應的布局,體會下main中布局的重要性!

更多關于Android相關內容感興趣的讀者可查看本站專題:《Android視圖View技巧總結》、《Android圖形與圖像處理技巧總結》、《Android開發(fā)入門與進階教程》、《Android調試技巧與常見問題解決方法匯總》、《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android基本組件用法總結》、《Android布局layout技巧總結》及《Android控件用法總結

希望本文所述對大家Android程序設計有所幫助。

相關文章

  • Android音頻開發(fā)之音頻采集的實現(xiàn)示例

    Android音頻開發(fā)之音頻采集的實現(xiàn)示例

    本篇文章主要介紹了Android音頻開發(fā)之音頻采集的實現(xiàn)示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-04-04
  • Android 登錄Web 時對cookie 處理

    Android 登錄Web 時對cookie 處理

    本文主要介紹 Android登錄web時對cookie的處理方法,這里cookie 的讀寫做了詳細介紹,并附有代碼進行講解,希望能幫到有需要的同學
    2016-07-07
  • Android實現(xiàn)調用攝像頭和相冊的方法

    Android實現(xiàn)調用攝像頭和相冊的方法

    這篇文章主要為大家詳細介紹了Android實現(xiàn)調用攝像頭和相冊的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-04-04
  • android getActivity.findViewById獲取ListView 返回NULL的方法

    android getActivity.findViewById獲取ListView 返回NULL的方法

    下面小編就為大家?guī)硪黄猘ndroid getActivity.findViewById獲取ListView 返回NULL的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-11-11
  • Android繪圖之Paint的使用方法詳解

    Android繪圖之Paint的使用方法詳解

    這篇文章主要給大家介紹了關于Android繪圖之Paint使用的相關資料,文中通過示例代碼介紹的非常詳細,并給大家介紹了DrawText 基線確定的方法,需要的朋友可以參考借鑒,下面隨著小編來一些學習學習吧。
    2017-11-11
  • Android自定義View之酷炫數(shù)字圓環(huán)

    Android自定義View之酷炫數(shù)字圓環(huán)

    這篇文章主要為大家詳細介紹了Android自定義View之酷炫數(shù)字圓環(huán),實現(xiàn)效果很酷,,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-01-01
  • Android性能優(yōu)化之利用強大的LeakCanary檢測內存泄漏及解決辦法

    Android性能優(yōu)化之利用強大的LeakCanary檢測內存泄漏及解決辦法

    本篇文章主要介紹了Android性能優(yōu)化之利用LeakCanary檢測內存泄漏及解決辦法,有興趣的同學可以了解一下。
    2016-11-11
  • Android編程實現(xiàn)帶有單選按鈕和復選按鈕的dialog功能示例

    Android編程實現(xiàn)帶有單選按鈕和復選按鈕的dialog功能示例

    這篇文章主要介紹了Android編程實現(xiàn)帶有單選按鈕和復選按鈕的dialog功能,結合具體實例形式分析了Android實現(xiàn)帶有單選按鈕的dialog對話框及帶有復選按鈕的dialog對話框相關操作技巧,需要的朋友可以參考下
    2017-09-09
  • Android設備上非root的抓包實現(xiàn)方法(Tcpdump方法)

    Android設備上非root的抓包實現(xiàn)方法(Tcpdump方法)

    通常我們在Android應用中執(zhí)行某個命令時會使用“Runtime.getRuntime().exec("命令路徑")”這種方式,但是當我們執(zhí)行抓包操作時,使用這條命令無論如何都不行,通過下面代碼打印結果發(fā)現(xiàn),該命令一定要在root權限下才能執(zhí)行,具體實現(xiàn)思路,請參考本教程
    2016-11-11
  • Handler與Android多線程詳解

    Handler與Android多線程詳解

    一開始,相信很多人都以為myThread中的run()方法會在一個新的線程中運行,但事實并非如此。以下代碼中的handler并沒有調用線程myThread的start()方法,而是直接調用了run()方法,這也就意味著實際上并沒有創(chuàng)建一個新的線程,只是在當前線程中調用run()方法而已
    2013-10-10

最新評論

岳阳市| 九龙县| 博乐市| 兴文县| 原阳县| 晋州市| 镇雄县| 民勤县| 安宁市| 建始县| 新津县| 和顺县| 宁津县| 义马市| 益阳市| 沧源| 西乌珠穆沁旗| 和政县| 天水市| 克山县| 夏邑县| 原阳县| 江津市| 台南市| 宜宾市| 图们市| 大足县| 苍溪县| 闽侯县| 麦盖提县| 宁津县| 普兰县| 策勒县| 高邮市| 黄平县| 敦化市| 班戈县| 开原市| 瑞昌市| 漯河市| 饶阳县|