android 字定义GridView 引用自己的定义布局
生活随笔
收集整理的這篇文章主要介紹了
android 字定义GridView 引用自己的定义布局
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
如果你這個自定義的 view要在xml中使用,那么必須使用構(gòu)造方法含有兩個參數(shù)或者兩個參數(shù)以上的。 否則一個參數(shù)的構(gòu)造方法就可以。
在構(gòu)造方法中使用 inflate(context, Rlayout.main_activity.xml, GripView)
public class CustomView extends ViewGroup {public CustomView(Context context, AttributeSet attrs) {super(context, attrs);inflate(context, R.layout.activity_main, this);}@Overrideprotected void onLayout(boolean changed, int l, int t, int r, int b) {} }調(diào)用了這個方法之后就可以直接在view中findViewById去尋找對應xml文件中的控件進行操作!!!
總結(jié)
以上是生活随笔為你收集整理的android 字定义GridView 引用自己的定义布局的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: NSIS FileOpen打开读写文件操
- 下一篇: hibernate demo 搭建