自定義ListView中實現多列和可變大小的元素:AsymmetricGridView
一個Android自定義ListView中實現多列和可變大小的元素。
Screenshots:
Usage
In your build.gradle
file:
repositories { maven { url 'https://github.com/felipecsl/m2repository/raw/master/' } // ... } dependencies { // ... compile 'com.felipecsl:asymmetricgridview:1.0.+' }
In your layout xml:
<com.felipecsl.asymmetricgridview.library.widget.AsymmetricGridView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="match_parent"/>
In your activity class:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listView = (AsymmetricGridView) findViewById(R.id.listView); // Choose your own preferred column width listView.setRequestedColumnWidth(Utils.dpToPx(this, 120)); final List<AsymmetricItem> items = new ArrayList<>(); // initialize your items array adapter = new ListAdapter(this, listView, items); listView.setAdapter(adapter); }
Supports resetting and appending more elements into the adapter:
// Will append more items at the end of the adapter. listView.getAdapter().appendItems(moreItems); // resetting the adapter items. Will clear the adapter // and add the new items. listView.getAdapter().setItems(items);
Toggle to enable/disable reordering of elements to better fill the grid
// Setting to true will move items up and down to better use the space // Defaults to false. listView.setAllowReordering(true); listView.isAllowReordering(); // true
Works with Android 2.3.x and above.
項目主頁:http://www.baiduhome.net/lib/view/home/1413857075528
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!