2010-12-17 1 views
2

は、レイアウトです:second_tvがフォーカスを取得したとき、予想通りフォーカスされたViewGroup内のTextViewのマーキーをアクティブにするにはどうすればよいですか?ここ

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 
    <RelativeLayout 
     android:id="@+id/first_tv_container" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:focusable="true" 
     android:background="@android:drawable/list_selector_background"> 
     <TextView 
      android:id="@+id/first_tv" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." 
      android:singleLine="true" 
      android:ellipsize="marquee" 
      android:duplicateParentState="true"/> 
    </RelativeLayout> 
    <TextView 
     android:id="@+id/second_tv" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." 
     android:singleLine="true" 
     android:ellipsize="marquee" 
     android:focusable="true" 
     android:background="@android:drawable/list_selector_background"/> 
</LinearLayout> 

、second_tvのマーキーがアクティブになります。 first_tv_containerがフォーカスを取得したとき、first_tvのマーキーも同様にしたいと思います。私はfirst_tvにduplicaParentState = trueを追加することがそのトリックを行うと思ったが、そうではない。ですから、私の質問は、TextViewのマーキーをフォーカスしたViewGroup(ListView以外、自動的に大文字小文字を正しく処理します)内で作業して、たくさんのものを拡張したり無効にしたりする標準的で簡単な方法ですか?

大丈夫

答えて

1

OK、私は何らかの方法を見つけました。

@Override 
protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) 
{ 
    super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); 

    setSelected(gainFocus); 
    dispatchSetSelected(gainFocus); 
} 

私が欲しかったものを正確に種類:私はdescendantFocusability =「blocksDescendants」を宣言し、次のオーバーライドを定義しているRelativeLayoutの拡張版としてfirst_tvする=「true」にフォーカス可能、およびインスタンス化さfirst_tv_container:私はアンドロイドを追加しました回避するが、それは今のところ行うだろう。

関連する問題