2010-12-17 1 views
2

다음은 레이아웃입니다.초점이 맞춰진 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가 포커스를 얻으면 second_tv의 선택 윤곽이 예상대로 활성화됩니다. first_tv_container가 포커스를 얻었을 때 first_tv의 선택 윤곽도 좋을 것입니다. 나는 first_tv에 duplicaParentState = true를 추가하는 것이 트릭을 할 것이라고 생각했지만 그렇지 않습니다. 그래서 내 질문은 것입니다 : TextView의 선택 윤곽을 포커스가있는 ViewGroup (ListView 이외의, 자동으로 대/소문자를 올바르게 처리하는) 내에서 작업하고 많은 내용을 확장하거나 재정의하지 않고도 쉽게 사용할 수 있습니까?

감사합니다

답변

1

그래, 나는 어떤 종류의 방법을 찾았습니다. 내가 원하는 물건의

@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 : 나는 안드로이드를 추가 피하기 위해,하지만 그것은 지금 할 것입니다.

관련 문제