【发布时间】:2021-09-24 04:46:31
【问题描述】:
我是 Android 新手,现在正在编写我的第一个应用程序。我有一个 ListView 呈现一系列项目,每个项目都有多个 TextView。我希望 ListView 中的每个项目都可以点击,并为点击设置动画。动画是我正在努力解决的问题。
我有 selectableItemBackground 属性,它可以在 TextView-by-TextView 的基础上完美运行。但是,这意味着点击动画只出现在特定的 TextView 上,而我希望它出现在整个列表项本身上。
这是我的 Android 视图。我知道这种行为是由于我将 selectableItemBackground 属性放在 TextView 元素上造成的,我只是想不出还有什么地方可以达到我想要的效果。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:gravity="center">
<TextView
android:id="@+id/past_game_update_timestamp"
android:foreground="?android:attr/selectableItemBackground"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:clickable="true"
android:padding="@dimen/small_padding"
android:textSize="@dimen/small_font_size" />
<TextView
android:id="@+id/past_game_start_timestamp"
android:foreground="?android:attr/selectableItemBackground"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:clickable="true"
android:padding="@dimen/small_padding"
android:textSize="@dimen/small_font_size" />
</LinearLayout>
【问题讨论】:
标签: android