[英]Gallery lose focus
我写了一个代码来放大图库中选定的图像,我不知道为什么每次滚动时图库都会失去焦点,这是我的代码。
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");
}
});
尝试lasview.getLayoutParams()
,然后在检索到的LayoutParams上设置值。
调用setLayoutParams()
会导致重新绘制/刷新,这可能会导致您的问题。
我自己这样解决了这个问题。
<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"/>
在活动中
@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;
}
这个对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.