自訂視圖(群組控制項),自訂視圖群組控制項

來源:互聯網
上載者:User

自訂視圖(群組控制項),自訂視圖群組控制項
前言


  Android自訂控制項主要分為兩種,一種是通過繼承View來實現自訂控制項,另一種是通過組合已有到控制項來實現自訂控制項,上篇文章自訂視圖(繼承View)我們介紹了下繼承View到方式,這篇文章簡單介紹下群組控制項來實現自訂控制項。

  有些情況我們需要通過組合已有到控制項來實現特定功能到控制群組建,比如一個應用到題頭,大概樣式如下
    

Java代碼


  通過群組控制項來實現自訂控制項到方式,是通過繼承一個ViewGrou對象來實現,比如LinearLayout, FrameLayout, RelativeLayout,等等,簡單實現如下所示

  

 1 public class CombinView extends RelativeLayout { 2  3     public CombinView(Context context, AttributeSet attrs) { 4         super(context, attrs); 5         LayoutInflater inflater = (LayoutInflater)context.getSystemService    (Context.LAYOUT_INFLATER_SERVICE); 6         RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.custom_view,this); 7  8     } 9 10 }

 

  其中需要注意到是RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.custom_view,this);方法,第二個參數this,用來表明inflate出來到layout添加到當前對象

custom_view.xml

  下面一段代碼就是自訂視圖的布局檔案內容,沒有什麼特別的,如下所示

  

 1 <?xml version="1.0" encoding="utf-8"?> 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 3     android:layout_width="match_parent" 4     android:layout_height="wrap_content" > 5  6     <TextView 7         android:id="@+id/tvShow" 8         android:layout_width="wrap_content" 9         android:layout_height="wrap_content"10         android:text="返回" />11 12     <TextView13         android:layout_width="wrap_content"14         android:layout_height="wrap_content"15         android:layout_alignParentRight="true"16         android:text="設定" />17 18     <RelativeLayout19         android:layout_width="match_parent"20         android:layout_height="wrap_content" >21 22         <TextView23             android:layout_width="match_parent"24             android:layout_height="wrap_content"25             android:gravity="center_horizontal"26             android:text="標題" />27     </RelativeLayout>28 29 </RelativeLayout>
後記

  這樣的話,一個簡單的組合自訂視圖就實現完成了,這篇和上篇文章介紹了自訂視圖的一些東西,雖然我們實現了自訂控制項,但是還有一點沒有提到,就是如何給自己的控制項定製自己的屬性,有了自己的屬性才算完整,在下篇會簡單介紹下自訂屬性的一些東西。

原文地址:http://www.cnblogs.com/luoaz/p/3983674.html

 


MFC 列表視圖控制項問題

清單控制項  m_List
m_List.SetExtendedStyle(LVS_SINGLESEL);// 好像有點bug , 這個屬性在 vc6.0裡是 checkbox 在ListCtrl裡.

對你的這個工程比較感興趣. 有想法一起研究
請聯絡 : 1939124823@qq.com
 
我的2003ppt/視圖/控制項工具箱/其他控制項/播放動畫的地區/屬性裡怎沒有“自訂”選項?

同問?我也想知道。。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.