当前位置: 代码迷 >> Android >> Android:在触摸事件中显示子视图
  详细解决方案

Android:在触摸事件中显示子视图

热度:101   发布时间:2023-08-04 12:40:55.0

我是Android开发人员的新手。 我正在尝试在父视图单击或选择时显示子视图。 这是我的代码:

<RelativeLayout
    android:id="@+id/relative_button"
    android:layout_width="match_parent"
    android:layout_height="52dp"
    android:onClick="login_click">
        <ImageView
            style="@style/button_image"
            android:id="@+id/button_image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/signin"
            android:contentDescription="@string/button_icon"
            android:layout_centerVertical="true"
            android:layout_toLeftOf="@+id/textView"
            android:visibility="invisible"/>
        <com.ontheway.app.TextViewPlus
            style="@style/button_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/button_login"
            android:id="@+id/textView" />
</RelativeLayout>

目前,ImageView不可见。 我想在单击或选择父级RelativeLayout时显示它。 我想知道是否可以通过选择器完成此操作,还是必须在Java中执行此操作?是否最好像现在这样动态添加ImageView或将其保留在XML中? 谢谢您的帮助。

使用onCLick属性,您的整个布局将响应点击。 这应该工作正常。 无论您将imageview放在此处还是在Java中动态添加它,似乎都是个人喜好而非硬性规定

  相关解决方案