Android记录material包下的好工具(Slider、ShapeableImageView)

记录一下,万一以后用到了呢?
导包

implementation 'com.google.android.material:material:1.2.1'

Slider

1633769669145.gif

代码



    
    

总长度和当前长度代码

android:valueTo="100f"
android:valueFrom="0f"
android:value="20f"

拖动时出现的大圆提示

app:haloColor="@color/mainColor"
app:haloRadius="20dp"//如果不想要,就设置为0dp

圆圈上面的数字提示框设置

app:labelBehavior="withinBounds"

他有floating、withinBounds、gone三种,gone肯定是不展示,经过我的测试设置floating在个别手机上面会有显示bug,看下图:


1633770131231.gif

lable没有消失,出现问题的手机是华为p10,小米10是好的。所以这里都用withinBounds模式。
滑块的设置

app:thumbColor="@color/ff666666"
app:thumbRadius="10dp"//圆的半径
app:thumbElevation="10dp"//悬浮阴影

进度条背景颜色设置

app:trackColorActive="@color/mainColor"//以拖动的区域
app:trackColorInactive="@color/ff666666"//未覆盖的区域

RangeSlider的话注意app:values="@array/initial_slider_values"


        0
        100
    

这样设置,默认从两端开始拖动
步长设置

android:stepSize="10"

每10的数字打个点。

ShapeableImageView

Screenshot_20211009_171046_com.example.demo.jpg

代码


    
        
        
        
    
    
        
        
        
    









当然这是简单的使用
主要注意cornerFamily,他有rounded和cut两种,如果需要圆角那就是rounded,如果需要多边形,那么需要cut。你可以把cornerFamily理解成设置这个属性控制图片的4个角,那么他肯定有单独设置某个角的功能





然后cornerSize可以设置具体数字,也能百分比。当然我们可以单独设置摸一个角。





你可能感兴趣的:(Android记录material包下的好工具(Slider、ShapeableImageView))