我有一个画廊,其适配器创建多个实例的LinearLayout一个画廊。那些线性布局实例有按钮,然而,当有人点击按钮时,他们不能拖动画廊。滚动的按钮
我的想法是具有用户可以通过滚动菜单。通常使用ScrollView完成的事情,但是因为我希望滚动的视图能够“捕捉”到当前的按钮页面,所以一个Gallery可以更好地工作。
这个问题是类似这样的:Android gallery of LinearLayouts
然而,当我已经解决了“按钮会出现点击”拖动问题的时候,我似乎无法让有它的工作就像一个滚动型呢,这些按钮可用作拖动区域的一部分。
任何提示?
不知道,如果代码是相关的,但在这里它是。
布局包含画廊:
<?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 ...如何在主要活动中实现此代码? – jayellos
谢谢泽西,救了我的屁股! – Leo
真的很好......谢谢zeh ... – kalandar