5

一部のウィジェットには定数contentDescriptionが適していますが、キャプション付きの画像ギャラリーなどの他のケースでは、UI に適切なアクセシビリティ ラベルが既にあります。を XMLImageViewcontentDescriptionラベル付けにリンクする方法はありますか?Textview

たとえば、このImageView定義の最後の (架空の) 行に実際に相当するものはありますか?

<LinearLayout>
    <ImageView
        android:id="@+id/image"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:contentDescription="@+id/label" />
    <TextView
        android:id="@+id/label"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
</LinearLayout>
4

1 に答える 1

13

の値がすでにわかっている場合はTextView、それを使用できます。

<LinearLayout>
    <ImageView
        android:id="@+id/image"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:contentDescription="@string/some_str" />
    <TextView
        android:id="@+id/label"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/some_str" />
</LinearLayout>

ただし、TextViewのコンテンツをプログラムで設定する場合は、 のコンテンツの説明についても同じことを行う必要がありますImageView。(このドキュメントを参照してください。)

String desc = "Foo Bar";
yourTextView.setText(desc);
yourImageView.setContentDescription(desc);
于 2012-08-18T23:17:23.803 に答える