android include進來的組件 調用其子元素


include標簽包裹着一個可復用的布局:

<include layout="@layout/footer_detail"
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

// 這里需要引入footer頁腳,以及調用其中的元素home,search, favorite
View footerLayout = findViewById(R.id.footer);
homeBtn = (ImageButton) footerLayout.findViewById(R.id.btn_home);

// 如下要膨脹一個布局,那么就需要從一個單獨的布局文件中加載,比如ListView的adapter中的ListItem...
// LayoutInflater inflater = LayoutInflater.from(this);
// View footerLayout = inflater.inflate(R.layout.footer_detail, null); //第一個參數為布局Id, 第二個參數為其父布局View


ref:
實例化inflate進來的組件與include進來的組件
http://blog.csdn.net/djun100/article/details/9624955

LayoutInflater的使用 
http://blog.csdn.net/zuolongsnail/article/details/6370035


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM