Android ——之流式布局
相信大家很多地方都用到了 一些流失布局 比如

像這種 布局的話在專案中很常見 所以為了方便大家 的使用 在這里 小編自己做了一個 第三方庫 不需要大家 直接從別的地方復制 粘貼別人的物體類啥的 直接 用我的三方庫 so 簡單
ok 話不多說 直接上代碼
首先是 jitpack的包這個毋庸置疑
maven { url 'https://jitpack.io' }
在build.gradle 中
implementation 'com.github.zhan0313:mingFlowLayout:1.0.6'
ok那么三方庫 完成了 接下來 上代碼
//這個 是我的 MainActivity 中的布局檔案
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.sming.mingflowlib.FlowLayout
android:id="@+id/flo"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayList<String > mList=new ArrayList<>();
mList.add("我愛祖國");
mList.add("我愛祖國的山");
mList.add("我愛祖國的水");
mList.add("我愛祖國的青山綠水");
mList.add("我愛我們家的陳女士");
mList.add("我愛她");
FlowLayout flo = findViewById(R.id.flo);
flo.setAlignByCenter(FlowLayout.AlienState.LEFT);
flo.setAdapter(mList, R.layout.item_flo, new FlowLayout.FlowSetData<String>() {
@Override
public void getCover(String item, FlowLayout.FlowViewHolder holder, View inflate, int position) {
holder.setText(R.id.tv_label_name,item);
}
});
}
}
**以上兩步 so簡單 這樣就完成了 一個簡單的 流失布局 此外強調一點 **
R.layout.item_flo 這個布局檔案 指的是子布局的檔案
接下來獻上小編的 git地址 大家要是有需要 可以看我的 源代碼
[專案地址] https://github.com/zhan0313/mingFlowLayout/tree/1.0.6
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/237098.html
標籤:其他
