一、Vlayout attach
Vlayout是一種適用於Android的布局框架,它能夠方便的實現通用的複雜布局,它的主要特點是支持嵌套、支持異步布局加載,並且提供了Flow、GridLayout、StaggeredGridLayout、LinearLayout和FrameLayout這幾種常見的布局方式。
Vlayout attach是Vlayout的核心類之一,它實現了RecyclerView的Layout Manager,同時支持Item復用、異步布局加載和多層布局嵌套。為了實現這個特性,需要在item.xml中添加一個vlayout屬性,並且將VlayoutManager設置給RecyclerView。
RecyclerView recyclerView = findViewById(R.id.recycler_view);
VlayoutManager layoutManager = new VlayoutManager();
recyclerView.setLayoutManager(layoutManager);
二、Playoutdoors
Playoutdoors是Vlayout的一個常用Component,它可以用來實現複雜布局。
Playoutdoors是使用Vlayout實現複雜布局的關鍵,在這裏面可以自由的組合多種布局方式,使得它可以與任何View混合在一起,同時可以應用於RecyclerView中。
//添加頭部
DelegateAdapter adapter = new DelegateAdapter(layoutManager, true);
adapter.addAdapter(new SingleLayoutAdapter(this, R.layout.item_title));
//添加中間內容
adapter.addAdapter(new SingleLayoutAdapter(this, R.layout.item_goods));
//添加底部
adapter.addAdapter(new SingleLayoutAdapter(this, R.layout.item_ad));
recyclerView.setAdapter(adapter);
三、Vlayout二級列表
Vlayout可以實現二級列表,不僅可以垂直放置,也可以橫向放置。它可以嵌套多個Vlayout實現很複雜的布局。
//初始化數據
List<Pair<String, List>> dataList = new ArrayList();
for (int i = 0; i < 10; i++) {
List childList = new ArrayList();
for (int j = 0; j < 10; j++) {
childList.add("我的寶貝" + j);
}
dataList.add(new Pair("分類" + i, childList));
}
//嵌套兩個Vlayout實現二級列表
DelegateAdapter adapter = new DelegateAdapter(layoutManager, false);
//Vlayout1實現垂直列表
adapter.addAdapter(new CategoryAdapter(dataList));
//Vlayout2實現橫向瀑布流
adapter.addAdapter(new DelegateAdapter(layoutManager)
.addAdapter(new HotGoodsAdapter(this)));
recyclerView.setAdapter(adapter);
四、PCB Layout
在使用Vlayout進行布局時,我們一般採用LinearLayout來實現最基本的列表布局,而PCB Layout與LinearLayout非常相似,但是比LinearLayout更加靈活,可以實現更多種複雜的布局方式。
PCB Layout最常用的屬性是paddding和margin,這兩個屬性可以將控件放置在一個大的布局中,從而使得整個界面顯得非常整潔。
//在XML文件中進行布局設置
五、Pla有透明的嗎
Pla(out)是一款全新的異步加載圖片框架,能夠高效地實現圖片的加載和緩存。它支持動態配置Options,並且可以將圖片加載到指定的控件中,同時它還支持圓角、帶邊框、高斯模糊、特殊形狀等各種高級需求。
Pla的圖片也可以設置透明,只需要在代碼中實現對應的Options即可。
//在代碼中使用Options設置圖片透明度
Options options = new Options();
options.setImageTransparency(0.5f);
image.load("http://example.com/image.jpg", options);
六、Playoutside
Playoutside是Vlayout中一個常用的組件,它可以在加載item之前,將其從頁面外加載進來,以達到加速加載的效果。同時它還可以優化Item復用的效果,避免出現大量的重複加載問題。
//使用Playoutside提高布局效率
DelegateAdapter adapter = new DelegateAdapter(layoutManager, true);
adapter.addAdapter(new SingleLayoutAdapter(this, R.layout.item_title));
adapter.addAdapter(new SingleLayoutAdapter(this, R.layout.item_goods).addVvItemView(new Playoutside()));
adapter.addAdapter(new SingleLayoutAdapter(this, R.layout.item_ad).addVvItemView(new Playoutside()));
recyclerView.setAdapter(adapter);
七、Playout下載
Vlayout提供了Playout下載功能,它可以適用於各種場景下異步圖片加載的效果。這種方式提供了一種更加高效的圖片加載方式,可以實現更好的用戶體驗。
//使用Playout下載圖片
DelegateAdapter adapter = new DelegateAdapter(layoutManager, true);
adapter.addAdapter(new SingleLayoutAdapter(this, R.layout.item_title));
adapter.addAdapter(new SingleLayoutAdapter(this, R.layout.item_goods)
.addVvItemView(new PlaVout()).addClick(this::openGoodsDetail));
adapter.addAdapter(new SingleLayoutAdapter(this, R.layout.item_ad).addVvItemView(new PlaGift()));
recyclerView.setAdapter(adapter);
八、Layout
Vlayout提供的Layout可以輕鬆構建複雜布局,它支持嵌套和複合布局,可以應用於Android系統中的各種場景下。
//使用Vlayout實現複雜布局
RecyclerView recyclerView = findViewById(R.id.recycler_view);
VlayoutManager layoutManager = new VlayoutManager();
recyclerView.setLayoutManager(layoutManager);
DelegateAdapter adapter = new DelegateAdapter(layoutManager, true);
adapter.addAdapter(new SingleLayoutAdapter(this, R.layout.item_title));
adapter.addAdapter(new SingleLayoutAdapter(this, R.layout.item_goods)
.addVvItemView(new PlaVout()).addClick(this::openGoodsDetail));
adapter.addAdapter(new SingleLayoutAdapter(this, R.layout.item_ad).addVvItemView(new PlaGift()));
recyclerView.setAdapter(adapter);
九、Playoutdoors中文翻譯
Playoutdoors可以直接翻譯為「布局門戶」,它能夠實現不同布局之間的互通,是Vlayout中最為重要的一個組件之一。
總結
Vlayout是一種非常通用的Android布局框架,它可以用來實現複雜布局和異步加載圖片,同時還支持二級列表、PCB Layout、Playoutside和Playout下載等多種常用組件。使用Vlayout可以輕鬆地構建出適用於各種場景的複雜布局,是Android開發非常值得掌握的技術。
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/193076.html