andorid權威編程指南 筆記

1 創建fragment

@Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fragment_arguments_support);

    if (savedInstanceState == null) {
        // First-time init; create fragment to embed in activity.
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        Fragment newFragment = MyFragment.newInstance("From Arguments");
        ft.add(R.id.created, newFragment);
        ft.commit();
    }
}

2 tools:text android:text區別

android:text --> what you would see while running the app

tools:text --> what you would see just on preview window (when you need to design layout, but won't it to see on layout in app)


xmlns:tools="http://schemas.android.com/tools"

tools可以告訴Android Studio,哪些屬性在運行的時候是被忽略的,只在設計佈局的時候有效。

3 RecyclerView.onBindViewHolder called only once


原因:Make sure you set layout_height =" wrap_content" of RecyclerView child item.

4 Only one item displaying in recycler view. 顯示列表的時候,有三條記錄,卻僅僅顯示第一條。

具體佈局:<RecyclerView> <RelativeLayout/> <TextView/>

                </RecyclerView>

方案: Change height of LinearLayout to wrap_content in itemlist.xml

android:layout_height="wrap_content"

That means : RecyclerView and RelativeLayout both need to set

layout_height="wrap_content"

 5 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章