www.久久久久|狼友网站av天堂|精品国产无码a片|一级av色欲av|91在线播放视频|亚洲无码主播在线|国产精品草久在线|明星AV网站在线|污污内射久久一区|婷婷综合视频网站

當前位置:首頁 > 芯聞號 > 充電吧
[導讀]報出異常的原因是由于少添加了構造方法,三個構造方法需要寫完整,不能只寫一個。參數為(Context, AttributeSet),其中第二個參數用來將xml文件中的屬性初始化。自定義控件若需要在xml

報出異常的原因是由于少添加了構造方法,三個構造方法需要寫完整,不能只寫一個。參數為(Context, AttributeSet),其中第二個參數用來將xml文件中的屬性初始化。

自定義控件若需要在xml文件中使用,就必須重寫帶如上兩個參數的構造方法。


package?sunny.example.layoutparamstaddrule;

import?android.content.Context;
import?android.util.AttributeSet;
import?android.widget.Button;
import?android.widget.RelativeLayout;
import?android.widget.RelativeLayout.LayoutParams;
import?android.widget.TextView;

public??class?TestView?extends?RelativeLayout{
	
	private?LayoutParams?mLayoutParams_1,mLayoutParams_2;
	Button?mButton;
	TextView?mTextView;
	public?TestView(Context?context)?{
		super(context);
		//?TODO?Auto-generated?constructor?stub
		mButton?=?new?Button(context);
		mTextView?=?new?TextView(context);
		init();
		
	}
	public?TestView(Context?context,?AttributeSet?attrs)?{
		super(context,?attrs);
		//?TODO?Auto-generated?constructor?stub
		mButton?=?new?Button(context);
		mTextView?=?new?TextView(context);
		init();
	}
	public?TestView(Context?context,?AttributeSet?attrs,?int?defStyle)?{
		super(context,?attrs,?defStyle);
		//?TODO?Auto-generated?constructor?stub
		mButton?=?new?Button(context);
		mTextView?=?new?TextView(context);
		init();
	}
	
	public?void?init(){
		
		mLayoutParams_1?=?new?LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
		mLayoutParams_1.addRule(RelativeLayout.ALIGN_TOP);
		addView(mButton,mLayoutParams_1);
		
		
		mLayoutParams_2?=?new?LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
		mLayoutParams_2.addRule(RelativeLayout.BELOW,?TRUE);
		mTextView.setText("Hey");
		addView(mTextView,mLayoutParams_2);
	}
}

自定義控件在XML文件中使用


LayoutPrams


RelativeLayout.LayoutParams extends ViewGroup.MarginLayoutParams
java.lang.Object ???? android.view.ViewGroup.LayoutParams ? ???? android.view.ViewGroup.MarginLayoutParams ? ? ???? android.widget.RelativeLayout.LayoutParamsRelativeLayout.LayoutParams(Context c, AttributeSet attrs) RelativeLayout.LayoutParams(int w, int h) RelativeLayout.LayoutParams(ViewGroup.LayoutParams source) RelativeLayout.LayoutParams(ViewGroup.MarginLayoutParams source) RelativeLayout.LayoutParams(RelativeLayout.LayoutParams source)Copy constructor.



RelativeLayout.LayoutParams的方法: public void addRule (int verb)

Adds a layout rule to be interpreted by the RelativeLayout. This method should only be used for constraints that don't refer to another sibling (e.g., CENTER_IN_PARENT) or take a boolean value (TRUE for true or 0 for false). To specify a verb that takes a subject, use addRule(int, int) instead.

ParametersOne of the verbs defined by RelativeLayout, such as ALIGN_WITH_PARENT_LEFT. public void addRule (int verb, int anchor)

Adds a layout rule to be interpreted by the RelativeLayout. Use this for verbs that take a target, such as a sibling (ALIGN_RIGHT) or a boolean value (VISIBLE).

ParametersOne of the verbs defined by RelativeLayout, such as ALIGN_WITH_PARENT_LEFT.The id of another view to use as an anchor, or a boolean value(represented asTRUE) for true or 0 for false). For verbs that don't refer to another sibling (for example, ALIGN_WITH_PARENT_BOTTOM) just use -1


RelativeLayout.LayoutParams.addRule() 方法,該方法有兩種重載方式:

addRule(int verb) :用此方法時,所設置節(jié)點的屬性不能與其它兄弟節(jié)點相關聯或者屬性值為布爾值(布爾值的屬性,設置時表示該屬性為 true,不設置就默認為 false),比如:addRule(RelativeLayout.CENTER_VERTICAL) 就表示在 RelativeLayout 中的相應節(jié)點是垂直居中的。


addRule(int verb, int anchor) :該方法所設置節(jié)點的屬性必須關聯其它的兄弟節(jié)點或者屬性為布爾值( 屬性為布爾值時,anchor 為 RelativeLayout.TRUE 表示 true,anchor 為0表示 false),比如:addRule(RelativeLayout.ALIGN_LEFT, R.id.date) 就表示 RelativeLayout 中的相應節(jié)點放置在一個 id 值為 date 的兄弟節(jié)點的左邊。

Public Constructorsverbverbanchor
本站聲明: 本文章由作者或相關機構授權發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內容真實性等。需要轉載請聯系該專欄作者,如若文章內容侵犯您的權益,請及時聯系本站刪除。
換一批
延伸閱讀

9月2日消息,不造車的華為或將催生出更大的獨角獸公司,隨著阿維塔和賽力斯的入局,華為引望愈發(fā)顯得引人矚目。

關鍵字: 阿維塔 塞力斯 華為

加利福尼亞州圣克拉拉縣2024年8月30日 /美通社/ -- 數字化轉型技術解決方案公司Trianz今天宣布,該公司與Amazon Web Services (AWS)簽訂了...

關鍵字: AWS AN BSP 數字化

倫敦2024年8月29日 /美通社/ -- 英國汽車技術公司SODA.Auto推出其旗艦產品SODA V,這是全球首款涵蓋汽車工程師從創(chuàng)意到認證的所有需求的工具,可用于創(chuàng)建軟件定義汽車。 SODA V工具的開發(fā)耗時1.5...

關鍵字: 汽車 人工智能 智能驅動 BSP

北京2024年8月28日 /美通社/ -- 越來越多用戶希望企業(yè)業(yè)務能7×24不間斷運行,同時企業(yè)卻面臨越來越多業(yè)務中斷的風險,如企業(yè)系統(tǒng)復雜性的增加,頻繁的功能更新和發(fā)布等。如何確保業(yè)務連續(xù)性,提升韌性,成...

關鍵字: 亞馬遜 解密 控制平面 BSP

8月30日消息,據媒體報道,騰訊和網易近期正在縮減他們對日本游戲市場的投資。

關鍵字: 騰訊 編碼器 CPU

8月28日消息,今天上午,2024中國國際大數據產業(yè)博覽會開幕式在貴陽舉行,華為董事、質量流程IT總裁陶景文發(fā)表了演講。

關鍵字: 華為 12nm EDA 半導體

8月28日消息,在2024中國國際大數據產業(yè)博覽會上,華為常務董事、華為云CEO張平安發(fā)表演講稱,數字世界的話語權最終是由生態(tài)的繁榮決定的。

關鍵字: 華為 12nm 手機 衛(wèi)星通信

要點: 有效應對環(huán)境變化,經營業(yè)績穩(wěn)中有升 落實提質增效舉措,毛利潤率延續(xù)升勢 戰(zhàn)略布局成效顯著,戰(zhàn)新業(yè)務引領增長 以科技創(chuàng)新為引領,提升企業(yè)核心競爭力 堅持高質量發(fā)展策略,塑強核心競爭優(yōu)勢...

關鍵字: 通信 BSP 電信運營商 數字經濟

北京2024年8月27日 /美通社/ -- 8月21日,由中央廣播電視總臺與中國電影電視技術學會聯合牽頭組建的NVI技術創(chuàng)新聯盟在BIRTV2024超高清全產業(yè)鏈發(fā)展研討會上宣布正式成立。 活動現場 NVI技術創(chuàng)新聯...

關鍵字: VI 傳輸協(xié)議 音頻 BSP

北京2024年8月27日 /美通社/ -- 在8月23日舉辦的2024年長三角生態(tài)綠色一體化發(fā)展示范區(qū)聯合招商會上,軟通動力信息技術(集團)股份有限公司(以下簡稱"軟通動力")與長三角投資(上海)有限...

關鍵字: BSP 信息技術
關閉
關閉