? ? ?本文是記錄項目開發中一些相對復雜但都比較實用的控件,這些控件都是基于自定義的方式去實現,如果有需要的朋友,這個可以作為一個參考,同時也做一個自我總結。
? ? (1)子項大小不一致的RecyclerView(占一個格子,兩個格子,四個格子。。。)
? ?
?注意:上面兩個圖示主要展示子項占用格子數(項目為5行5列,下面看不見的可以上拉顯示,其中駕駛模式占2行2列,儀表盤亮度占2行1列,靜音占1行1列,行列可以根據自己需求設計,但不大于最大行,另外上面兩圖展示了中間的格子是可以互相拖動的)。
(2)豎直的seekbar(有間隔)
? ? ?
注意:此為自定義的上下滑動條,非android自帶的seekbar,可以上下拖動,可以根據自己需求定制(添加豎軸線,只顯示一個滑塊,滑塊間隔,軸中各個點的大小,顏色等)
(3)橫向可以多個選項切花的按鈕
代碼:
<com.google.android.material.tabs.TabLayoutandroid:id="@+id/tab_layout_time"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="@drawable/shape_time_switch_track_off"android:orientation="horizontal"app:tabBackground="@android:color/transparent"app:tabIndicator="@drawable/shape_tab_indicator"app:tabMinWidth="300dp"app:tabIndicatorColor="@color/white"app:tabIndicatorFullWidth="true"app:tabIndicatorHeight="49dp"app:tabMaxWidth="490dp"app:tabRippleColor="@android:color/transparent"app:tabSelectedTextColor="@android:color/holo_blue_light"app:tabTextColor="@color/white"app:layout_constraintTop_toTopOf="parent"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toRightOf="parent"><com.google.android.material.tabs.TabItemandroid:id="@+id/tab_time_12"android:layout_width="wrap_content"android:layout_height="wrap_content"android:gravity="center"android:text="@string/about_time_12_24"android:textSize="15sp" /><com.google.android.material.tabs.TabItemandroid:id="@+id/tab_time_24"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/about_time_24_12"android:textSize="15sp" /><com.google.android.material.tabs.TabItemandroid:id="@+id/tab_time_48"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/about_time_48_24"android:textSize="15sp" /></com.google.android.material.tabs.TabLayout>
注意:其中的TabItem可以寫多個,滿足3個或者以上的子選項(如果使用switch則只能是兩個選項互相切換,不能有多個選項切換) ? ? ?
(4)豎向滾動選擇器
以上是項目開發中遇到的一部分需要自定義的view,有需要的可以參考下,現在做一個記錄,后續如果還有更多的需要定制的view,這邊會陸陸續續地上傳在這個文章里面,當然如果你也有很好地很使用項目中的,或者項目中開發很常見需要定制的控件,可以分享分享,謝謝。
整個自定義view(包含上述所有自定義控件)的代碼地址: