2016-08-26 22 views
1

我正在努力使現有的Android應用程序可訪問,並且發現它非常令人沮喪,許多事情本該工作。Android輔助功能 - 使用ImageView進行內容分組無法正常工作

我想組一起爲剛剛在Google Codelabs example喜歡說明中的內容,但仍使手勢導航欄中的內容可成爲焦點的一部分:

我有一個LinearLayout一個Fragment與垂直方向爲根查看三個RelativeLayouts,其中每個包含一個ImageView和一個TextView

layout

就像在codelabs,我已經設置了RelativeLayout到可獲得焦點,爲ImageViews我已經設置了ContentDescription爲null,因爲它們是純粹的裝飾。

這是XML佈局這些RelativeLayouts與根LinearLayout之一:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@android:color/white" 
    android:orientation="vertical" 
    tools:context="com.my.fancyapp.fragments.OtherFragment"> 

    <RelativeLayout 
     android:id="@+id/item_youtube" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/other_item_height" 
     android:focusable="true" 
     android:background="?attr/selectableItemBackground" 
     android:padding="@dimen/other_item_padding"> 

     <ImageView 
      android:id="@+id/ivYouTube" 
      android:layout_width="@dimen/other_icon_width" 
      android:contentDescription="@null" 
      android:layout_height="match_parent"/> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="@dimen/other_text_margin_left" 
      android:text="YouTube" 
      android:textAppearance="@style/ArtistTextAppearance" /> 
    </RelativeLayout> 
    ... 
</LinearLayout> 

Fragment,我設置一個onClickListener每個RelativeLayout,其鏈接到立體圖(YouTube頻道,Facebook頁面或與IMPRESSUM網頁視圖)並裝載ImageViewPicasso

itemYoutube.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 
      Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(youTubeUrl)); 
      startActivity(intent); 
      } 
     } 
    }); 

Picasso.with(getActivity()) 
     .load(R.drawable.icon_youtube) 
     .fit() 
     .centerInside() 
     .into(iconYoutube); 

itemYoutube.setContentDescription(getString(R.string.youtube)); 

現在proble M是想點擊一個項目,然後通過滑動到下一個項目導航導致文本中強調,不通過導航到下一個RelativeLayout

enter image description here

有沒有人有一個想法,爲什麼重點跳轉到TextView而不是下一個RelativeLayout

我曾嘗試以下:

  • 設置ContentDescription爲RelativeLayouts在XML
  • 設置ContentDescription爲TextViews爲null(可能不太好)
  • 改變順序時設置的內容說明
  • TextViews設置爲可對焦:false
  • 刪除了ContentDescription的RelativeLayouts,這導致導航到TextViews,而不是強調整個RelativeLayout爲希望

難道是一個問題,即違背Codelabs例子,我有RelativeLayout內的ImageView,而當時只有TextViews應該全部被讀出來?或者是否有什麼時候通過代碼動態地設置xml和其他類似ClickListener的值? 我完全無能爲力。

回答

0

嘿,我有一個類似的問題!我的解決方案是將我的佈局的根容器設置爲可調焦(android:focusable="true")。然後奇蹟般地內部可調焦容器開始正常運行。