日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android调小边框距离,RecyclerView Item 的分割线 距边框距离问题总结

發布時間:2025/4/16 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android调小边框距离,RecyclerView Item 的分割线 距边框距离问题总结 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

哈, 首先? 今天Design 提了一個需求,廢話少說~~! 上圖android

分割線 在中間顯示,距離左邊 邊距是66px 右邊依然是66px。ios

剛開始接到這個需求,感受還闊以,挺簡單的,可是在實現中 又有問題了,app

怎么設置 都不能距離左右 有間距,上網上查依然沒有解決方案。ide

網上有設置一個 View 而后給這個 View 設置寬高 顏色 可是 在我這里不能用,布局

由于我是自定義的控件 直接繼承 ViewGroup 直接用 View 會有問題 影響了滑動控件。spa

個人解決方案以下:code

個人 item 布局 是自定義的。在不改變自定義控件前提下 加上這個間隔線。xml

item 布局以下很是的簡單: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 下一章會講 很簡單的一個標簽。繼承

@BindView(R.id.recycler_history)

EasyRecyclerView recyclerHistory;

recyclerHistory.addItemDecoration(getRecyclerViewDivider(R.drawable.search_history_solid));

RecyclerHistory 不用說 就是RecyclerView 歷史記錄。給RecyclerView每一個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">

而后就完美解決了這個不改變 item 布局的狀況下給每一個 item 添加間隔線。

但愿對大家有所幫助 哈哈! 雖然沒有粉絲。

總結

以上是生活随笔為你收集整理的android调小边框距离,RecyclerView Item 的分割线 距边框距离问题总结的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。