【发布时间】:2011-11-14 20:42:26
【问题描述】:
我有一个画廊,它的适配器创建了几个 LinearLayout 实例。然而,那些线性布局实例有按钮,当有人点击按钮时,他们无法拖动图库。
我的想法是有一个用户可以滚动浏览的菜单。通常使用 ScrollView 可以完成的事情,但因为我希望滚动视图“捕捉”到当前按钮页面,所以画廊效果更好。
这个问题和这个问题类似:Android gallery of LinearLayouts
但是,虽然我已经修复了拖动时“按钮似乎被点击”的问题,但通过让按钮作为拖动区域的一部分工作,我似乎无法让它像 ScrollView 那样工作。
有什么提示吗?
不确定代码是否相关,但在这里。
包含画廊的布局:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Gallery
android:id="@+id/gallery"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:fadingEdge="none"
android:spacing="0dp"/>
</FrameLayout>
填充图库的测试活动:
import com.zehfernando.display.widgets.ZGallery;
public class ScrollTestActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.scrolltest);
Gallery gallery = (Gallery) findViewById(R.id.gallery);
gallery.setAdapter(new LayoutAdapter(this));
}
public class LayoutAdapter extends BaseAdapter {
private Context mContext;
public LayoutAdapter(Context c) {
mContext = c;
}
public int getCount() {
return 3;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = vi.inflate(R.layout.scrolllayout, null);
v.setMinimumWidth(getWindowManager().getDefaultDisplay().getWidth());
return v;
}
}
}
画廊内框架的布局:
<?xml version="1.0" encoding="utf-8"?>
<com.zehfernando.display.widgets.ScrollableLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/buttonRegister"
android:layout_width="200dp"
android:layout_height="72dp"
android:text="REGISTER"/>
<Button
android:id="@+id/buttonUnregister"
android:layout_width="match_parent"
android:layout_height="72dp"
android:text="UNREGISTER" />
</com.zehfernando.display.widgets.ScrollableLinearLayout>
“ScrollableLinearLayout”只是我的类,它扩展了 LinearLayout 以覆盖 onPressed。
【问题讨论】:
标签: android button android-layout gallery android-linearlayout