20
我以編程方式像horizontalview那樣創建,然後如何以編程方式傳遞AttributeSet。如何在android中以編程方式創建時傳遞AttributeSet
我的構造是這樣的:
public HorizontalListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
我試試這個:
mHlvSimpleList= new HorizontalListView(mcontext,R.style.niceview);
錯誤:
The constructor HorizontalListView(Context, int) is undefined
在style.xml
<style name="niceview">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
如何在horizontalistview構造函數中傳遞AttributeSet中的匹配參數?
https://stackoverflow.com/a/25457076/1105214 – samosaris 2018-03-05 20:12:11
我發現它最容易簡單地進行一個自定義視圖的佈局並將它膨脹,如果你有多個稍微有點不同的實例,只需創建一個基礎樣式並用'