相关疑难解决方法(0)

Android Lollipop CardView上的涟漪效应

我试图让CardView时,通过设置在Android触摸显示连锁反应:所描述的行为在XML文件中backgound属性这里 Android开发者页面上,但它不工作.根本没有动画,但是调用onClick中的方法.我也尝试过按照这里的建议创建一个ripple.xml文件,但结果相同.

CardView出现在活动的XML文件中:

<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="155dp"
    android:layout_height="230dp"
    android:elevation="4dp"
    android:translationZ="5dp"
    android:clickable="true"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:onClick="showNotices"
    android:background="?android:attr/selectableItemBackground"
    android:id="@+id/notices_card"
    card_view:cardCornerRadius="2dp">

</android.support.v7.widget.CardView> 
Run Code Online (Sandbox Code Playgroud)

我对android开发比较陌生,所以我可能会犯一些明显的错误.
提前致谢.

android android-layout android-cardview android-5.0-lollipop

164
推荐指数
8
解决办法
10万
查看次数

使用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万
查看次数

Android-L CardView视觉触摸反馈

任何人都可以向我解释如何在CardView中实现Google I/O 2014中展示的一些视觉触摸反馈.

以下是我在XML中使用CardView的方法,可能有一些我想念的小东西,所以我只是想知道是否有人可以帮助我?

<!-- A CardView -->
<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/CardView_1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginTop="10dp" 
    card_view:cardCornerRadius="4dp"
    android:elevation="2dp">

    <LinearLayout
        android:id="@+id/LinearLayout_1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:onClick="RunSomeMethod"">

    <!-- Main CardView Content In Here-->

    </LinearLayout> </android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)

android android-layout android-cardview android-5.0-lollipop

64
推荐指数
3
解决办法
4万
查看次数

如何在代码中获取attr引用?

我希望通过代码从属性中获取指向引用.在我的xml布局中,我可以轻松地获得引用的drawable,如下所示:

android:background="?attr/listItemBackground"
Run Code Online (Sandbox Code Playgroud)

属性引用由我的主题设置.我想看看是否可以通过代码获得引用的drawable.

我可以通过创建样式attr并在自定义视图中读取值来解决这个问题,但在这种情况下,我想弄清楚这是否可行而不做所有这些.我认为这是可能的,但我还没有找到获得该属性参考的方法.

谢谢!

android android-layout

45
推荐指数
1
解决办法
3万
查看次数

如何以编程方式在LinearLayout上设置Ripple效果?

我想将背景设置android.R.attr.selectableItemBackground为a LinearLayout.使用XML时没有问题(可行)

<LinearLayout
    android:id="@+id/llMiner"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="?android:attr/selectableItemBackground"
    android:clickable="true" >
Run Code Online (Sandbox Code Playgroud)

...但我必须在java代码中这样做,所以我试过这个

llMiner.setClickable(true);
llMiner.setBackgroundResource(android.R.attr.selectableItemBackground);
Run Code Online (Sandbox Code Playgroud)

......它不起作用,事实上我得到了NotFoundException第二行.所以在我尝试了这个变体后认为资源是一个颜色.

llMiner.setClickable(true);
llMiner.setBackgroundColor(android.R.attr.selectableItemBackground);
Run Code Online (Sandbox Code Playgroud)

这个没有启动异常,但是......不起作用(按下时没有改变背景,但是状态改变按下它必须这样做)...任何建议?

android background clickable android-linearlayout

37
推荐指数
1
解决办法
2万
查看次数