android fadingedge,RecyclerView的FadingEdge参数

当滑动列表需要两侧阴影时,可以设置RecyclerView的FadingEdge属性:

android:id="@+id/recyclerView"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:fadingEdgeLength="50dp"

android:fadingEdge="horizontal"

android:requiresFadingEdge="horizontal" />

fadingEdgeLength参数为阴影的长度,当API Level>14 应该使用requiresFadingEdge

这样RecyclerView两端都会有阴影

43b4ec31992e395fdf54542316f9c07c.png

如果仅需左侧或者是右侧需要 需要重写View类的获取阴影长度的方法

将不需要阴影的部分返回参数设置为0即可

import android.content.Context

import android.util.AttributeSet

import androidx.recyclerview.widget.RecyclerView

class FadingEdgeRecyclerView : RecyclerView {

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以通过继承 Preference 类来实现自定义布局,并在其中添加一个 Button,然后为该 Button 添加点击事件。下面是一个简单的示例代码: ```java public class CustomPreference extends Preference { private Button mButton; public CustomPreference(Context context, AttributeSet attrs) { super(context, attrs); setWidgetLayoutResource(R.layout.custom_preference); } @Override public void onBindViewHolder(PreferenceViewHolder holder) { super.onBindViewHolder(holder); mButton = (Button) holder.findViewById(R.id.custom_button); mButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 处理点击事件 } }); } } ``` 在布局文件 `custom_preference.xml` 中添加一个 Button: ```xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="?android:attr/listPreferredItemHeight" android:gravity="center_vertical" android:paddingStart="?android:attr/listPreferredItemPaddingStart" android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"> <TextView android:id="@android:id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceListItem" android:singleLine="true" android:ellipsize="marquee" android:fadingEdge="horizontal" android:textColor="@android:color/primary_text_light" /> <Button android:id="@+id/custom_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> </LinearLayout> ``` 最后,在设置界面的 XML 文件中使用自定义的 Preference: ```xml <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> ... <com.example.CustomPreference android:key="custom_preference" android:title="Custom Preference" /> </PreferenceScreen> ``` 这样就可以在设置界面中显示一个自定义布局的 Preference,其中包含一个 Button,并且为该 Button 添加了点击事件。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值