gpt4 book ai didi

android - "snapping"horizo​​ntalscrollview 像主屏幕一样

转载 作者:太空宇宙 更新时间:2023-11-03 13:37:37 25 4
gpt4 key购买 nike

我想知道如何使 horizo​​ntalscrollview 像主屏幕一样“对齐”,这意味着我的 horizo​​ntalscrollview 中有两个页面,我可以在每个页面之间滑动。

最佳答案

你有两个选择。

使用 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;
}
}

关于android - "snapping"horizo​​ntalscrollview 像主屏幕一样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5014542/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com