2011-12-13 4 views
0

내 갤러리에서 선택한 이미지를 업 사이징하는 코드를 작성했습니다. 스크롤 할 때마다 왜 갤러리가 포커스를 잃을 지 모르겠고, 여기 내 코드가 있습니다.갤러리가 포커스를 잃습니다

gallery.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 
     public void onItemSelected(AdapterView<?> parent, View v, 
       int position, long id) { 

      if (lasview != null) 
       lasview 
         .setLayoutParams(new Gallery.LayoutParams(130, 195)); 
      lasview = v; 
      v.setLayoutParams(new Gallery.LayoutParams(170, 230)); 

     } 

     public void onNothingSelected(AdapterView<?> parent) { 
      // System.out.println("NOTHING SELECTED"); 

     } 
    }); 

답변

0

나는 이런 문제를 직접 풀었다. 활동

@Override 
public boolean onKeyDown(int keyCode, KeyEvent event) { 
if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) { 

     gl.onKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT, null); 

     return true; 
    } 
    if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) { 

     gl.onKeyDown(KeyEvent.KEYCODE_DPAD_LEFT, null); 

     return true; 
    } 
      return false; 

}에서

 <Gallery 
     android:id="@+id/gallery1" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="50" 
     android:nextFocusDown="@+id/gallery1" 
     android:nextFocusLeft="@+id/gallery1" 
     android:nextFocusRight="@+id/gallery1" 
     android:nextFocusUp="@+id/gallery1" 
     android:focusable="false" 
     android:clickable="false" 
     android:focusableInTouchMode="false" 
     android:descendantFocusability="afterDescendants"/> 

그것은 나를 위해 작동합니다.

1

lasview.getLayoutParams()을 시도하고 대신 검색된 LayoutParams에 값을 설정하십시오.
setLayoutParams()을 호출하면 다시 그리기/새로 고침이 발생하여 문제가 발생할 수 있습니다.

+0

getView 자체는 setLayoutParams를 포함하고 있기 때문에 포커스를 잃게됩니다. 해결책이 있습니까? 그것은 나에게 매우 중요하기 때문에? – Vervatovskis

+0

당신이 변경을 한 후에 포커스를 강제하기를 원하는 갤러리/뷰에'requestFocus()'를 추가 할 수도 있습니다. – Jave

관련 문제