我想知道如何使 horizontalscrollview 像主屏幕一样“对齐”,这意味着我的 horizontalscrollview 中有两个页面,我可以在每个页面之间滑动。
你有两个选择。
使用 ViewFlipper 或 android Gallery。
我更喜欢你使用 android Gallery,因为它会受到控制并且是更好的方法。
在 Default Android Gallery Example 中,您将找到 developer.android.com 站点在它使用的适配器和 getView() 方法中,返回一个 ImageView。您以一种返回膨胀的 xml 布局的方式操作您的代码,如下面的代码
class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
TypedArray a = obtainStyledAttributes(R.styleable.HelloGallery);
mGalleryItemBackground = a.getResourceId(
R.styleable.HelloGallery_android_galleryItemBackground, 0);
a.recycle();
}
public int getCount() {
return 5;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
convertView = LayoutInflater.from(mContext).inflate(R.layout.ownview, null);
return convertView;
}
}
我是一名优秀的程序员,十分优秀!