xml布局內容總結(四)--Android

來源:互聯網
上載者:User

標籤:find   mod   控制項   內容   方法   values   布局   span   找不到   

(1)對於xml編寫介面較複雜的情況下,使用include會使得編寫和查看更清楚

<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" 
>
            <include android:id="@+id/hi1" layout="@layout/health_info1" />
            <include android:id="@+id/hi2" layout="@layout/health_info2" />
            <include android:id="@+id/hi3" layout="@layout/health_info3" />
            <include android:id="@+id/hi4" layout="@layout/health_info4" />
            <include android:id="@+id/hi5" layout="@layout/health_info5" />
            
        </LinearLayout>

這裡health_info1到health_info5是5個布局檔案,相應於介面中的5個模組,每一個模組單獨200行左右,假設在單獨的模組中,不論是改動還是查看都比較easy,假設不適用include,整個布局檔案就是1000行左右。無論是改動還是查看都比較麻煩,類似於代碼中函數的調用。

CheckBox  hiCbPs1;

hiCbPs1=(CheckBox)findViewById(R.id.hi1).findViewById(R.id.hicbps1);

這是代碼中的使用方法

(2)自己定義view的使用。在開發產品時,有時候會碰到一些須要自己進行繪製的view增加到介面中

加入到到xml中的使用方法

<com.jxj.view.BigDialView 
               android:id="@+id/healthstatedial"
               android:layout_width="fill_parent"
               android:layout_height="200dip"
               android:layout_margin="5dip"
               android:layout_gravity="center"
               android:scaleType="centerInside"
               />

com.jxj.view  是包名   BigDialView是自己定義的類名   com.jxj.view.BigDialView是完整的路徑 

這裡常常easy出錯的問題就是xml中找不到該類,原因通常是未定義這個類,還是就是包名或類名寫錯導致xml找不到

(3)這個是在LoonAndroid架構中看到的。認為挺好用

基本全部的控制項都會用到這兩條語句

android:layout_width="fill_parent"

android:layout_height="wrap_content"

在LoonAndroid架構中看到了這樣的使用方法比較簡單,用一條語句替換了

<RelativeLayout
        android:id="@+id/top_head"
        style="@style/w_full_h_wrap"
        android:background="@drawable/head_back"
        android:orientation="horizontal" >

等同於

<RelativeLayout
        android:id="@+id/top_head"  
android:layout_width="fill_parent"
android:layout_height="wrap_content"
        android:background="@drawable/head_back"
        android:orientation="horizontal" >

想要使用這樣的方法。僅僅需在values檔案夾下加入

themes_basic.xml


<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">


    <!-- 全螢幕展開 -->
    <style name="w_h_full">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">fill_parent</item>
    </style>


    <!-- 高度和螢幕高度一樣 寬度自適應 -->
    <style name="w_wrap_h_full">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">fill_parent</item>
    </style>


    <!-- 寬度和螢幕寬度一樣 高度自適應 -->
    <style name="w_full_h_wrap">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>
    </style>


    <!-- 固定自身大小 -->
    <style name="w_wrap_h_wrap">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
    </style>

</resources>




xml布局內容總結(四)--Android

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.