所以我正在尝试向我的应用程序实现类似动画的下拉菜单,并禁用触摸其布局以防止用户反复点击视图。
我尝试使用这样的透明布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_signup_step_one_mainLayout"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/activity_signup_step_one_wrapper"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/activity_signup_step_one_stepImageWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<ImageView
android:id="@+id/activity_signup_step_one_stepImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/step1"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/activity_signup_step_one_orangEmailWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="@drawable/background2"
android:layout_below="@+id/activity_signup_step_one_stepImageWrapper">
<ImageView
android:id="@+id/activity_signup_step_one_orangEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/orangemail"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/activity_signup_step_one_dropdownTitleWrapper"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/activity_signup_step_one_orangEmailWrapper">
<TextView
android:id="@+id/activity_signup_step_one_dropdownTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/stepOneTitle"/>
<!--
<RelativeLayout
android:id="@+id/activity_signup_step_one_dropdownTitleWrapper_filler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false">
</RelativeLayout>
-->
</RelativeLayout>
<RelativeLayout
android:id="@+id/activity_signup_step_one_dropdownTextWrapper"
android:orientation="vertical"
android:gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/activity_signup_step_one_dropdownTitleWrapper">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/stepOneMessage"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/activity_signup_step_one_touchDisabler"
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
标识为activity_signup_step_one_touchDisabler
的最后一个布局是覆盖整个包装器布局的透明布局。
我在我的代码中使用它:
RelativeLayout dropDown = (RelativeLayout)findViewById(R.id.activity_signup_step_one_dropdownTitleWrapper);
RelativeLayout dropDownMessage = (RelativeLayout)findViewById(R.id.activity_signup_step_one_dropdownTextWrapper);
dropDownMessage.setVisibility(View.INVISIBLE);
dropDown.setOnClickListener(translateHandler);
dropDownMessage.setLayoutAnimationListener(new Animation.AnimationListener() {
RelativeLayout touchDisabler = (RelativeLayout)findViewById(R.id.activity_signup_step_one_touchDisabler);
@Override
public void onAnimationStart(Animation animation) {
touchDisabler.setClickable(true);
}
@Override
public void onAnimationEnd(Animation animation) {
touchDisabler.setClickable(false);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
所以基本上当按下dropDown
时,使用滑动动画显示并隐藏TextView
下面的dropDownMessage
。
我尝试将touchDisabler
设置为可点击onAnimationStart()
的透明布局,并且无法点击onAnimationEnd()
,但我仍然可以重复点击它,动画只是停留在那里每个水龙头都会闪烁整个文本视图。
如何在此处停止点击?