我在Nexus 5上运行它.这是我的CardView代码的一部分:
CardView cardView = new CardView(getActivity());
cardView.setRadius(4);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 400);
lp.setMargins(32, 16, 32, 16);
cardView.setLayoutParams(lp);
cardView.setContentPadding(50, 50, 50, 50);
...
cardView.setForeground(selectedItemDrawable);
Run Code Online (Sandbox Code Playgroud)
这是我如何获得selectedItemDrawable:
int[] attrs = new int[] { R.attr.selectableItemBackground };
TypedArray ta = getActivity().obtainStyledAttributes(attrs);
selectedItemDrawable = ta.getDrawable(0);
ta.recycle();
Run Code Online (Sandbox Code Playgroud)
当我点击卡片时,不会出现与selectedItemDrawable一起出现的波纹(它看起来与没有前景设置完全相同).我正在运行5.0,所以这看起来很奇怪,因为appcompat文档只说它不适用于pre-Lollipop设备.有人知道为什么会这样吗?最低API级别为16,目标为21.
android android-cardview rippledrawable android-5.0-lollipop
在我的应用程序中,我想创建一个填充整个视图的涟漪.因为它不能正常工作我创建了一个最小的示例应用程序,并在那里尝试但没有成功.
我的布局看起来像这样:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent" android:padding="16dp">
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ripple"
android:onClick="onViewClicked" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我的drawable定义如下:
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#1E88E5"
android:radius="0dp">
<item
android:id="@android:id/mask"
android:drawable="@android:color/white" />
</ripple>
Run Code Online (Sandbox Code Playgroud)
这是一个视频当前的样子.我希望这个圈子(我认为它正式称为热点)从middel成长,直到它填满整个圈子View.我不是在谈论有意识地设置为0dp的纹波半径.你有什么想法我能做到这一点吗?
编辑:最后我想实现这样的目标.
对于每个不想阅读所有答案的人:我设法实现它并为此创建一个repo.可以在项目中自由使用,并向我发送拉取请求.
android ripple android-resources android-drawable rippledrawable
为了描述我的问题,我创建了一个小例子
我有imagelay和textview的线性布局.对于linearlayout,我将波纹绘制为背景.但是当我点击或长按在imageview下的linearlayout波纹动画节目时.如何在imageview上显示动画?
main.xml中
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/linear"
android:layout_width="200dp"
android:layout_height="200dp"
android:background="@drawable/ripple"
android:clickable="true"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="100dp"
android:src="@mipmap/index" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is ripple test"
android:textColor="#FF00FF00" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
绘制-V21/ripple.xml:
<?xml version="1.0" encoding="utf-8"?>
<ripple
xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#FFFF0000">
<item>
<shape android:shape="rectangle">
<solid android:color="#FF000000"/>
</shape>
</item>
</ripple>
Run Code Online (Sandbox Code Playgroud)
绘制/ ripple.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle">
<corners android:radius="3dp" />
<solid android:color="#FFFF0000" />
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="rectangle">
<corners android:radius="3dp" />
<solid android:color="#FFFF0000" />
</shape>
</item> …Run Code Online (Sandbox Code Playgroud) 我正在使用selectableItemBackgroundBorderless添加波纹ImageView.我的预期行为是圆形波纹,扩大视图大小.不幸的是,波纹被视角限制.如何解决这个问题?
默认状态:
压制状态:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/nav_instruction_container"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:background="@drawable/nav_gradient_bg"
android:padding="20dp">
<ImageView
android:id="@+id/nav_sign"
android:layout_width="wrap_content"
android:layout_height="46dp"
android:layout_centerVertical="true"
android:scaleType="centerInside"
android:adjustViewBounds="true"
/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/nav_sign"
android:layout_marginLeft="24dp"
android:layout_marginStart="24dp"
android:layout_marginRight="24dp"
android:layout_marginEnd="24dp"
android:textColor="@color/white"
android:textSize="24sp"
android:textStyle="bold"
android:maxLines="2"
tools:text="A644 Shudehill asdfkjasdf asdfasdf asdfsss"
android:ellipsize="marquee"
/>
<TextView
android:id="@+id/subTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:layout_toRightOf="@+id/nav_sign"
android:layout_marginLeft="24dp"
android:layout_marginStart="24dp"
android:layout_marginRight="24dp"
android:layout_marginEnd="24dp"
android:textColor="@color/white"
android:textSize="17sp"
tools:text="via Church St"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
app:srcCompat="@drawable/ic_nav_queue_sheet_icon_light"
android:id="@+id/nav_queue"
android:scaleType="centerInside"
android:foreground="?attr/selectableItemBackgroundBorderless"
android:adjustViewBounds="true"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) android android-button android-view material-design rippledrawable
我试图对Spinner下拉项目应用涟漪效果,如下所示:
activity.java
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.array_name, R.layout.simple_spinner_dropdown_item);
adapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item);
Spinner mSpinner = (Spinner) findViewById(R.id.spinner);
mSpinner.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)
simple_spinner_dropdown_item.xml
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/spinner_ripple"
android:ellipsize="marquee"
android:gravity="center_horizontal"
android:padding="10dip"
android:singleLine="true"
android:textSize="14sp" />
Run Code Online (Sandbox Code Playgroud)
spinner_ripple.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<ripple android:color="?android:attr/colorControlHighlight">
<item><shape>
<solid android:color="@android:color/white" />
</shape>
</item>
</ripple>
</item>
</selector>
Run Code Online (Sandbox Code Playgroud)
但是在下拉列表中,它仅适用于第一个项目,并且仅当前选择的项目是第一个项目时的另一个项目.在所有其他情况下,它用波纹颜色填充背景项(没有涟漪效果).我的代码哪里错了?
已经尝试过:无法在下拉项目布局的背景上设置固定颜色并在Spinner元素下移动涟漪效果,如下所示:
simple_spinner_dropdown_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:ellipsize="marquee"
android:gravity="center_horizontal"
android:padding="10dip"
android:singleLine="true"
android:textSize="14sp" />
Run Code Online (Sandbox Code Playgroud)
activity_layout.xml
<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
android:dropDownSelector="@drawable/spinner_ripple" …Run Code Online (Sandbox Code Playgroud) android android-appcompat android-spinner material-design rippledrawable
我正在尝试将触摸反馈添加到LinearLayout,这类似于API级别21中的常规Button反馈,就像在此示例中一样,并且到目前为止还没有成功.
我已经定义了一个像这样的标准波纹可绘制:
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight">
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="?android:colorAccent" />
</shape>
</item>
Run Code Online (Sandbox Code Playgroud)
并使用了Google 在此提供的StateListAnimator :
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true" android:state_pressed="true">
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="translationZ"
android:valueTo="@dimen/touch_raise"
android:valueType="floatType" />
</item>
<item>
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="translationZ"
android:valueTo="0dp"
android:valueType="floatType" />
</item>
Run Code Online (Sandbox Code Playgroud)
在定义动画师和波纹可绘制之后,我将它们添加到我的LinearLayout中,如下所示:
<LinearLayout
android:id="@+id/linearLayout"
android:clickable="true"
android:focusable="true"
android:orientation="horizontal"
android:background="@drawable/ripple"
android:stateListAnimator="@anim/touch_elevation">
Run Code Online (Sandbox Code Playgroud)
我的想法是使用这个LinearLayout作为一个按钮,因为它更容易插入各种类型的文本并在其中处理ImageView定位(而不是按钮drawables).
只要视图的背景根据此问题没有透明度,就可以单独添加涟漪效果或动画.
我不确定这是否是与上述问题相关的问题,但看到标准按钮设法同时采用波纹和高程动画反馈,我认为在其他视图中也可以实现这种效果.
任何洞察这个问题将不胜感激.
android rippledrawable android-5.0-lollipop android-elevation
我有这样的观点
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button"
android:background="@drawable/ripple"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
Run Code Online (Sandbox Code Playgroud)
和ripple.xml一样
<?xml version="1.0" encoding="utf-8"?>
<ripple
xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight" >
<item android:id="@android:id/mask"
android:drawable="@android:color/white" />
</ripple>
Run Code Online (Sandbox Code Playgroud)
一切都很好.当我触摸视图时,它给了我涟漪效果.我正在寻找的是重复从代码开始视图上的波纹动画.将其显示为不确定的进展.波浪一直在荡漾.
就像是
Runnable runnable = new Runnable() {
@Override
public void run() {
RippleDrawable drawable = (RippleDrawable) button.getBackground();
drawable.showRipples(true, true); // <-- This is needed
handler.postDelayed(runnable, 500);
}
};
Run Code Online (Sandbox Code Playgroud)
这该怎么做?
java android android-animation rippledrawable android-5.0-lollipop
在寻找一段时间之后,我无法找到答案......
我有一个带有物品的回收者视图,当选择这些物品时,它们具有红色背景和白色文本(事先背景为白色,文本为黑色).为此,我使用选择器.
我最近试图为此添加一个涟漪效果,但除非我长时间点击该项目,项目的背景直接变为红色而没有波纹.我假设这是因为选择器状态state_selected覆盖了sate_pressed上的纹波?
有谁知道有没有办法解决这个问题?这是我使用的选择器代码:
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@android:color/holo_red_dark" >
<item>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="@drawable/ripple"
android:state_pressed="true"/>
<item
android:drawable="@android:color/holo_red_dark"
android:state_selected="true"/>
<item android:drawable="@android:color/white"/>
</selector>
</item>
</ripple>
Run Code Online (Sandbox Code Playgroud)
提前致谢!
android ripple rippledrawable android-5.0-lollipop android-recyclerview
我搜索了所有的东西并进行了实验,但没有运气NavigationView.
itemIconTint,itemTextColor并itemBackground有效地工作ripple.但问题state selected不起作用selector drawable
我也创造drawable-v21并投入ripple_navigation_selector.xml
我的目标是当再次打开抽屉时,之前选择的项目应为黄色,例如.通知项目
NavigationView 在main_layout.xml中
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="@color/black"
app:headerLayout="@layout/header"
app:itemIconTint="@drawable/navigation_view_icon_tint_selector"
app:itemTextColor="@drawable/navigation_view_text_selector"
app:menu="@menu/drawer"
app1:itemBackground="@drawable/ripple_navigation_selector"
/>
Run Code Online (Sandbox Code Playgroud)
ripple_navigation_selector.xml 内 drawable-v21
<item
android:id="@android:id/mask"
android:drawable="@drawable/navigation_selector"/>
<item android:drawable="@drawable/navigation_selector"/>
Run Code Online (Sandbox Code Playgroud)
navigation_selector.xml 内 drawable-v21
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@color/left_light_yellow" android:state_pressed="true"></item>
<item android:drawable="@color/left_light_yellow" android:state_activated="true"></item>
<item android:drawable="@color/left_light_yellow" android:state_checked="true"></item>
<item android:drawable="@android:color/black"></item>
Run Code Online (Sandbox Code Playgroud)
颜色字符串命名 left_light_yellow
<color name="left_light_yellow">#F6CE20</color>
Run Code Online (Sandbox Code Playgroud) android rippledrawable android-5.1.1-lollipop android-navigationview
我正在使用第三方库,有一种方法使用DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_IN);.当我在Android 5.0 +中测试我的应用程序时,没有问题并且运行良好.但是当它涉及到android 4.4.4时,它引发了一个异常:
05-09 13:15:15.030 26447-26447/com.wizchen.athit E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.wizchen.athit, PID: 26447
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.wizchen.athit/com.wizchen.athit.view.activity.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2271)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2320)
at android.app.ActivityThread.access$800(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1269)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5117)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.support.v4.graphics.drawable.DrawableWrapperDonut.setCompatTintMode(DrawableWrapperDonut.java:278)
at android.support.v4.graphics.drawable.DrawableCompatBase.setTintMode(DrawableCompatBase.java:48)
at android.support.v4.graphics.drawable.DrawableCompat$BaseDrawableImpl.setTintMode(DrawableCompat.java:99)
at android.support.v4.graphics.drawable.DrawableCompat.setTintMode(DrawableCompat.java:400)
at com.wizchen.athit.lib.AppThemeEngine.util.TintHelper.createTintedDrawable(TintHelper.java:359)
at com.wizchen.athit.lib.AppThemeEngine.viewprocessors.ToolbarProcessor.process(ToolbarProcessor.java:117)
at com.wizchen.athit.lib.AppThemeEngine.viewprocessors.ToolbarProcessor.process(ToolbarProcessor.java:44)
at com.wizchen.athit.lib.AppThemeEngine.ATE.postApply(ATE.java:209)
at com.wizchen.athit.lib.AppThemeEngine.ATEActivity.onStart(ATEActivity.java:60)
at com.wizchen.athit.view.activity.MainActivity.onStart(MainActivity.java:68)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1183)
at android.app.Activity.performStart(Activity.java:5359)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2244) …Run Code Online (Sandbox Code Playgroud)