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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

android代码设置点击涟漪,android – 为自定义CompoundButton添加涟漪效果

發布時間:2024/8/1 编程问答 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android代码设置点击涟漪,android – 为自定义CompoundButton添加涟漪效果 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我有以下自定義CompoundButton:

public class CustomCompoundButton extends CompoundButton {

public CustomCompoundButton(Context context) {

this(context, null);

}

public CustomCompoundButton(Context context, AttributeSet attrSet) {

super(context, attrSet);

setup();

}

private void setup() {

setBackgroundResource(R.drawable.button_selector);

setGravity(Gravity.CENTER);

setClickable(true);

}

}

在將布局添加到布局后,我從代碼中設置了Button的寬度和高度:

button.getLayoutParams().width = myWidth;

button.getLayoutParams().height = myHeight;

button_selector.xml:

android:drawable="@drawable/button_checked"

android:state_checked="true" />

android:drawable="@drawable/button_unchecked"

android:state_checked="false" />

button_checked.xml:

android:shape="oval">

button_unchecked.xml:

android:shape="oval">

android:width="2dp"

android:color="?colorAccent" />

這按預期工作,未選中時按鈕為空圓圈,選中時為實心圓圈.

問題是我無法在此行為之上添加漣漪效應.

我試圖將選擇器包裝在ripple標簽中,如下所示:

android:color="#ffffff">

android:drawable="@drawable/button_checked"

android:state_checked="true" />

android:drawable="@drawable/button_unchecked"

android:state_checked="false" />

這種方法存在多個問題:

>背景形狀被漣漪完全覆蓋,它們不再可見(無論它們是否被檢查)

背景形狀應該保持不變,我只想在點擊按鈕時添加漣漪效果(選中或取消選中)

>漣漪效應的半徑太大,它們相互重疊

紋波半徑應與我的按鈕半徑相同.

我不知道如何做這項工作,真的很感激任何建議.

總結

以上是生活随笔為你收集整理的android代码设置点击涟漪,android – 为自定义CompoundButton添加涟漪效果的全部內容,希望文章能夠幫你解決所遇到的問題。

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