在Android的触摸滑轮上查看翻转?滑轮、Android

2023-09-05 01:17:01 作者:有种抚摸叫嘴巴子,!

我要实现的触摸滑轮上的ViewFlipper。例如。我有两个图像。起初,ViewFlipper显示的第一个图像。现在我扔从右到左的观点。第一个图像视图滑出左,第二张幻灯片从左侧。我可以实现它通过这种帖子。但我想滚动的图像。也就是说,在ACTION_MOVE事件我想要做的触摸滚动。例如,当我移动触摸从右到左将甩到多大的触摸动作。在该时间,输出应该部分地显示两个图像。

如何做到这一点?我必须测量屏幕水平(高度和放大器;宽度)。例如:codeS是更有帮助。

解决方案

 包com.appaapps.flipper;

进口android.app.Activity;
进口android.content.Context;
进口android.graphics *。
进口android.os.Bundle;
进口android.view.MotionEvent;
进口android.view.View;
进口android.widget.ViewFlipper;
// ------------------------------------------------ ------------------------------
//翻转 - 菲利普 -  [R布伦南在gmail.com
// ------------------------------------------------ ------------------------------
公共类FlipperActivity延伸活动{
    ViewFlipper F;
    drawView函数A,B,C;
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        F =新ViewFlipper(本);
        A =新的drawView函数(这一点,AAAAA);
        B =新drawView函数(这一点,BBBBB);
        C =新drawView函数(这一点,CCCCC);
        f.addView(一);
        f.addView(B);
        f.addView(C);
        的setContentView(F);
    }
    // ------------------------------------------------ ------------------------------
    // 绘制
    // ------------------------------------------------ ------------------------------
    一流的drawView函数扩展视图实现View.OnTouchListener {
        最后文本字符串;
        drawView函数(上下文的背景下,文本字符串){
            超(上下文);
            文本=文本;
            setOnTouchListener(本);
        }
        公共无效的OnDraw(帆布油画){
            super.onDraw(画布);
            涂料P =新的油漆();
            p.setColor(为0xffffffff);
            p.setTextSize(20);
            Canvas.drawText(文字,0,20,p)的;
        }
        公共布尔onTouch(视图V,MotionEvent事件){
            最终诠释一个= event.getAction();
            若(a == MotionEvent.ACTION_DOWN){
                最终诠释我= f.getDisplayedChild(),N = f.getChildCount();
                f.setDisplayedChild((1 + 1)%N);
            }
            返回true;
        }
    }
}
 

I have to achieve that the Touch Scroll on the ViewFlipper. For Example. I have two Images. At First, ViewFlipper shows an First Image. Now I Flung the view from right to left. The First Image view Slide out left and the Second Slide in from Left. I can achieve it By this Post. But I want to Scroll the image. That is, on the Action_Move Event I want to do Touch Scroll. For Example, when I move the touch from right to left it will flung how much the touch moves. on that time the output should show both images partly.

河北省电缆滑车 翻转滑车

How to do that? What I have to measure the Screen levels(height & width). Example codes are more helpful.

解决方案

package com.appaapps.flipper;

import android.app.Activity;
import android.content.Context;
import android.graphics.*;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ViewFlipper;
//------------------------------------------------------------------------------
// Flipper - Philip R Brenan at gmail.com
//------------------------------------------------------------------------------
public class FlipperActivity extends Activity {
    ViewFlipper f;
    DrawView a, b, c;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        f = new ViewFlipper(this);
        a = new DrawView(this, "aaaaa");
        b = new DrawView(this, "BBBBB");
        c = new DrawView(this, "ccccc");
        f.addView(a);
        f.addView(b);
        f.addView(c);
        setContentView(f);
    }
    //------------------------------------------------------------------------------
    // Draw 
    //------------------------------------------------------------------------------
    class DrawView extends View implements View.OnTouchListener {
        final String text;
        DrawView(Context Context, String Text) {
            super(Context);
            text = Text;
            setOnTouchListener(this);
        }
        public void onDraw(Canvas Canvas) {
            super.onDraw(Canvas);
            Paint p = new Paint();
            p.setColor(0xffffffff);
            p.setTextSize(20);
            Canvas.drawText(text, 0, 20, p);
        }
        public boolean onTouch(View v, MotionEvent event) {
            final int a = event.getAction();
            if (a == MotionEvent.ACTION_DOWN) {
                final int i = f.getDisplayedChild(), n = f.getChildCount();
                f.setDisplayedChild((i + 1) % n);
            }
            return true;
        }
    }
}