标签: touch-feedback

使用RecyclerView和CardView触摸反馈

我很想为我的开源库启用触摸反馈.

我创造了一个RecyclerView和一个CardView.该CardView包含不同的区域不同的onClick动作.现在,如果用户点击卡中的任何位置,我很乐意触发Ripple效果,但我无法实现此行为.

这是我的listitem,您也可以在GitHub上找到它:https://github.com/mikepenz/AboutLibraries/blob/master/library/src/main/res/layout/listitem_opensource.xml

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true"
    android:background="@drawable/button_rect_normal"/>

<LinearLayout
    android:padding="6dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <LinearLayout
        android:gravity="center_vertical"
        android:paddingLeft="8dp"
        android:paddingRight="8dp"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/libraryName"
            android:textColor="@color/title_openSource"
            android:textSize="@dimen/textSizeLarge_openSource"
            android:textStyle="normal"
            android:layout_width="0dp"
            android:layout_weight="5"
            android:layout_height="wrap_content"
            android:ellipsize="end"
            android:maxLines="1"/>

        <TextView
            android:id="@+id/libraryCreator"
            android:textColor="@color/text_openSource"
            android:textStyle="normal"
            android:layout_width="0dp"
            android:layout_weight="2"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dp"
            android:gravity="right"
            android:maxLines="2"
            android:textSize="@dimen/textSizeSmall_openSource"/>
    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="1px"
        android:layout_marginTop="4dp"
        android:background="@color/dividerLight_openSource"/>

    <TextView
        android:id="@+id/libraryDescription"
        android:textSize="@dimen/textSizeSmall_openSource"
        android:textStyle="normal"
        android:textColor="@color/text_openSource"
        android:padding="8dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:maxLines="20">
    </TextView>

    <View
        android:id="@+id/libraryBottomDivider"
        android:layout_width="match_parent"
        android:layout_height="1px"
        android:layout_marginTop="4dp"
        android:background="@color/dividerLight_openSource"/>

    <LinearLayout
        android:id="@+id/libraryBottomContainer"
        android:gravity="center_vertical"
        android:paddingLeft="8dp"
        android:paddingTop="4dp"
        android:paddingRight="8dp" …
Run Code Online (Sandbox Code Playgroud)

android touch-feedback android-cardview rippledrawable android-recyclerview

67
推荐指数
7
解决办法
5万
查看次数

当用户点击它时,蓝色突出显示在ImageView上

我有一个带有ImageView和TextView的LinearLayout"卡".我想要在用户点击它时突出显示该卡.有关示例,请参见http://www.youtube.com/watch?v=Yx1l9Y7GIk8&feature=share&t=15m17s.

通过设置可以轻松完成TextView android:background="@drawable/blue_highlight".下面是res/drawable/blue_highlight.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_selected="true" android:drawable="@color/selected"/>
  <item android:state_pressed="true" android:drawable="@color/pressed"/>
  <item android:drawable="@color/bg_window"/>
</selector>
Run Code Online (Sandbox Code Playgroud)

但这对ImageView不起作用,因为图像在前面而背景不可见.如何为ImageView创建半透明色的触摸高光效果?

android android-imageview touch-feedback

5
推荐指数
1
解决办法
5989
查看次数

为每个按钮启用触摸反馈

随着Android Studio我有一些Buttons,我想,当我点击他们,你可以看到一种运动是确认您已经点击的Button.有没有办法在没有创建新xml文件的情况下执行此操作selector?我想做那样的事情(我认为这是默认颜色):

在此输入图像描述 什么时候是正常的

在此输入图像描述 什么时候按下

我有这个,但它什么都没做:

Button b = (Button)findViewById(R.id.btn);
    b.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN ) {
                return true;
            }

            return false;
        }
    });
Run Code Online (Sandbox Code Playgroud)

android button touch-feedback

5
推荐指数
1
解决办法
3148
查看次数