[英]View is not accessible by talkback after animation
面臨一個非常奇怪的問題,無法在此處或任何其他博客中找到任何解決方案。
最初,視圖是不可見的,並且使用AlphaAnimation和ScaleAnimation使其可見。
Animation代碼
public void scaleView(View v, int delay) {
AnimationSet animatorSet = new AnimationSet(true);
animatorSet.setFillAfter(true);
animatorSet.setInterpolator(new LinearOutSlowInInterpolator());
AlphaAnimation animation1 = new AlphaAnimation(0.0f, 1.0f);
animation1.setDuration(200);
animation1.setStartOffset(delay);
ScaleAnimation fadeIn = new ScaleAnimation(0.5f, 1f, 0.5f, 1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
fadeIn.setDuration(200);
fadeIn.setStartOffset(delay);
animatorSet.addAnimation(animation1);
animatorSet.addAnimation(fadeIn);
animatorSet.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
v.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
v.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
v.startAnimation(animatorSet);
}
看法
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/llContainerMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@color/app_bg_f8"
android:gravity="center"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/rlFacebook"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="@dimen/dp_20"
android:layout_marginEnd="@dimen/dp_20"
android:layout_marginBottom="@dimen/dp_10"
android:contentDescription="@string/lbl_login_with_facebook"
android:importantForAccessibility="yes"
android:visibility="invisible">
<LinearLayout
android:id="@+id/llLoginWithFacebook"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_facebook_login_32"
android:minHeight="@dimen/dp_48">
<ImageView
android:layout_width="25dp"
android:layout_height="30dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="@dimen/dp_16"
android:scaleType="center"
android:src="@drawable/ic_facebook_logo" />
<View
style="@style/ShadowVertical"
android:layout_marginStart="@dimen/dp_10"
android:layout_marginEnd="@dimen/dp_10" />
<TextView
android:id="@+id/txtFacebook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="@dimen/dp_10"
android:gravity="center_vertical"
android:maxLines="1"
android:text="@string/lbl_login_with_facebook"
android:textColor="@color/white"
android:textSize="@dimen/sp_16" />
</LinearLayout>
<ImageView
android:id="@+id/imgLoginWithFacebook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/llLoginWithFacebook"
android:layout_alignTop="@+id/llLoginWithFacebook"
android:layout_alignEnd="@id/llLoginWithFacebook"
android:layout_alignBottom="@id/llLoginWithFacebook"
android:background="@drawable/bg_ripple_32" />
</RelativeLayout>
</RelativeLayout>
我努力使其易於訪問
1) 增加內容說明:
android:contentDescription="@string/lbl_login_with_facebook"
2)在視圖中添加內容描述就足夠了,但仍然無法正常工作,因此在 animation 添加之后我添加了焦點並通過以下代碼段告訴編譯器它很重要:
v.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
v.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
但是,仍然沒有運氣集中注意力。 誰能幫我弄清楚如何使它可以訪問?
我認為您的代碼中有一個簡單的錯誤。 嘗試改變這個:
v.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
對此
v.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.