안드로이드에서 텍스트 뷰 또는 이미지 뷰에 파급 효과를 설정하는 방법은 무엇입니까?
Android Studio에서 textview 및 imageview에 파급 효과를 설정하고 싶습니다. 내가 어떻게 해?
참조 : http://developer.android.com/training/material/animations.html ,
http://wiki.workassis.com/category/android/android-xml/
<TextView
.
.
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
/>
<ImageView
.
.
.
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
/>
잔물결을 TextView / ImageView의 크기로 제한하려면 다음을 사용하십시오.
<TextView
android:background="?attr/selectableItemBackground"
android:clickable="true"/>
(더 좋아 보인다)
잔물결 효과에 대해서는 아래 답변을 참조하십시오.
Textview 또는 뷰에서 리플 :
android:clickable="true"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackgroundBorderless"
버튼 또는 이미지 뷰에 리플 :
android:foreground="?android:attr/selectableItemBackgroundBorderless"
안드로이드 리플 배경을 사용할 수 있습니다
시작 효과
final RippleBackground rippleBackground=(RippleBackground)findViewById(R.id.content);
ImageView imageView=(ImageView)findViewById(R.id.centerImage);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
rippleBackground.startRippleAnimation();
}
});
애니메이션 중지 :
rippleBackground.stopRippleAnimation();
<TextView
android:id="@+id/txt_banner"
android:layout_width="match_parent"
android:text="@string/banner"
android:gravity="center|left"
android:layout_below="@+id/title"
android:background="@drawable/ripple_effect"
android:paddingLeft="15dp"
android:textSize="15sp"
android:layout_height="45dp" />
이것을 드로어 블에 추가하십시오
<?xml version="1.0" encoding="utf-8"?>
<!--this ribble animation only working for >= android version 21-->
<ripple
xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/click_efect" />
이 시도.
위의 답변 외에도 UI 편집기의 경고를 피하기 위해 집중 가능
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:focusable="true"
이 시도. 이것은 나를 위해 일했습니다.
android:clickable="true"
android:focusable="true"
android:background="?android:attr/selectableItemBackground"
In the case of the well voted solution posted by @Bikesh M Annur (here) doesn't work to you, try using:
<TextView
...
android:background="?android:attr/selectableItemBackgroundBorderless"
android:clickable="true" />
<ImageView
...
android:background="?android:attr/selectableItemBackgroundBorderless"
android:clickable="true" />
Also, when using android:clickable="true"
add android:focusable="true"
because:
"A widget that is declared to be clickable but not declared to be focusable is not accessible via the keyboard."
In addition to @Bikesh M Annur's answer, be sure to update your support libraries. Previously I was using 23.1.1 and nothing happened. Updating it to 23.3.0 did the trick.
Or you can try to use this library (android 9+): RippleEffect
Integration
dependencies {
compile 'com.github.traex.rippleeffect:library:1.3'
}
Usage:
<com.andexert.library.RippleView
android:id="@+id/more"
android:layout_width="?android:actionBarSize"
android:layout_height="?android:actionBarSize"
android:layout_toLeftOf="@+id/more2"
android:layout_margin="5dp"
rv_centered="true">
<ImageView
android:layout_width="?android:actionBarSize"
android:layout_height="?android:actionBarSize"
android:src="@android:drawable/ic_menu_edit"
android:layout_centerInParent="true"
android:padding="10dp"
android:background="@android:color/holo_blue_dark"/>
</com.andexert.library.RippleView>
Best way is using libraries. This is one of them. Just add its dependency and put below code in xml before each elements that needs ripple effect:
<com.balysv.materialripple.MaterialRippleLayout
android:id="@+id/ripple"
android:layout_width="match_parent"
android:layout_height="wrap_content">
'developer tip' 카테고리의 다른 글
CSS를 사용하여 '필수 필드'별표를 자동으로 추가하여 입력 구성 (0) | 2020.08.06 |
---|---|
Xcode에서“To Do”주석을 표시하려면 어떻게해야합니까? (0) | 2020.08.06 |
Rails 3 또는 Ruby에서 지속 시간을 시간 : 분 : 초 (또는 이와 유사한)로 변환 (0) | 2020.08.06 |
종료 코드 1 (링커를 보려면 -v 사용), Xcode 8, Swift 3으로 링커 명령이 실패했습니다. (0) | 2020.08.06 |
JavaScript를 사용하여 이미지가 서버에 있는지 확인 하시겠습니까? (0) | 2020.08.06 |