android调小边框距离,RecyclerView Item 的分割线 距边框距离问题总结
哈, 首先? 今天Design 提了一個(gè)需求,廢話少說(shuō)~~! 上圖android
分割線 在中間顯示,距離左邊 邊距是66px 右邊依然是66px。ios
剛開始接到這個(gè)需求,感受還闊以,挺簡(jiǎn)單的,可是在實(shí)現(xiàn)中 又有問題了,app
怎么設(shè)置 都不能距離左右 有間距,上網(wǎng)上查依然沒有解決方案。ide
網(wǎng)上有設(shè)置一個(gè) View 而后給這個(gè) View 設(shè)置寬高 顏色 可是 在我這里不能用,布局
由于我是自定義的控件 直接繼承 ViewGroup 直接用 View 會(huì)有問題 影響了滑動(dòng)控件。spa
個(gè)人解決方案以下:code
個(gè)人 item 布局 是自定義的。在不改變自定義控件前提下 加上這個(gè)間隔線。xml
item 布局以下很是的簡(jiǎn)單:blog
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="@dimen/px_100"
android:clickable="true"
app:ios="true"
app:leftSwipe="true"
app:swipeEnable="true">
//自定義的TextView
android:id="@+id/tv_word"
android:layout_width="match_parent"
android:layout_height="@dimen/px_100"
android:layout_centerVertical="true"
android:layout_marginStart="@dimen/px_14"
android:drawableLeft="@drawable/icon_search_history"
android:drawablePadding="@dimen/px_14"
android:gravity="center_vertical"
android:paddingLeft="@dimen/px_66"
android:maxEms="16"
android:singleLine="true"
android:textColor="@color/color_white_transparency_10"
android:textSize="@dimen/px_21" />
android:id="@+id/bt_del"
android:layout_width="@dimen/px_140"
android:layout_height="@dimen/px_100"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:background="@color/search_history_delete_bg"
android:gravity="center"
android:text="刪除"
android:textColor="@color/color_white"
android:textSize="@dimen/px_22" />
而后再 Fragment 中 BindView 下一章會(huì)講 很簡(jiǎn)單的一個(gè)標(biāo)簽。繼承
@BindView(R.id.recycler_history)
EasyRecyclerView recyclerHistory;
recyclerHistory.addItemDecoration(getRecyclerViewDivider(R.drawable.search_history_solid));
RecyclerHistory 不用說(shuō) 就是RecyclerView 歷史記錄。給RecyclerView每一個(gè)item添加間隔線。
/**
* 獲取分割線
*
* @param drawableId 分割線id
* @return
*/
public RecyclerView.ItemDecoration getRecyclerViewDivider(@DrawableRes int drawableId) {
DividerItemDecoration itemDecoration = new DividerItemDecoration(mContext, DividerItemDecoration.VERTICAL);
itemDecoration.setDrawable(ContextCompat.getDrawable(mContext, drawableId));
return itemDecoration;
}
xml 布局 以下:
android:insetLeft="66px"
android:insetRight="66px">
而后就完美解決了這個(gè)不改變 item 布局的狀況下給每一個(gè) item 添加間隔線。
但愿對(duì)大家有所幫助 哈哈! 雖然沒有粉絲。
總結(jié)
以上是生活随笔為你收集整理的android调小边框距离,RecyclerView Item 的分割线 距边框距离问题总结的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android界面不可见键盘隐藏功能,A
- 下一篇: android fragment 退出程