其他分享
首页 > 其他分享> > 在图像android之间滑动

在图像android之间滑动

作者:互联网

我对Android动画和手势比较陌生.

我有15张想要滑动的图像.屏幕上一次只显示一个图像,当我在第一张图像上滑动L-> R时,第二张图像显示,依此类推 – 就像幻灯片一样.我查看了Android Gallery教程,但我不希望显示缩略图.我的理解是使用ImageView并不断更改图像.这是正确的方法还是有更好的方法?

解决方法:

这样你就不会看到狡猾的效果.

有一种方法可以与画廊一起做.

像这样生活galery:

<Gallery xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:id="@+id/HorizontalGallery"
    android:gravity="center_vertical" android:spacing="2px"/>

在getview上你必须:

public View getView(int position, View convertView, ViewGroup parent) {

ImageView i = new ImageView(_Context);

i.setImageResource(R.drawable.YourPicture);
i.setLayoutParams(new Gallery.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));

//setting the scale:

int viewWidthtmp;
int viewHeighttmp;

if(getHeight() == 0)
{
    if(_horizGallery.getWidth() == 0){
        viewWidthtmp = _horizGallery.getWidth();
        viewHeighttmp = _horizGallery.getHeight();
    }
    else
    {
        viewWidthtmp = _screenWidth;
        viewHeighttmp = _screenHeight;
    }

//getting the size of the image.
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true; //returns null, but fills the out methods
bm = BitmapFactory.decodeResource(getResources(), R.drawable.YourPicture, o);
if(o.outHeight> viewHeight || o.outWidth> viewWidth) 
   {i.setScaleType(ImageView.ScaleType.CENTER_INSIDE);}
else
   {i.setScaleType(ImageView.ScaleType.FIT_CENTER);}

//DO NOT ADD the line below
//i.setBackgroundResource(mGalleryItemBackground);

return i;

}

您还必须声明2个全局变量变量并在活动的OnCreate中初始化它们.

public class ScrollingGallery extends Activity
{
    private int _screenWidth;
    private int _screenHeight;


...

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.scrollingallery);

        Display display = getWindowManager().getDefaultDisplay(); 
        _screenWidth = display.getWidth();
        _screenHeight = display.getHeight();

...

之后,您只需要使用计时器制作图库滚动.

如果我没有弄错的话,这应该适用于整页画廊.代码有点长,我只是写了它,所以可能有一个bug.

标签:android,gestures
来源: https://codeday.me/bug/20190614/1237605.html