當前位置:首頁 » 安卓系統 » android控制項滑動

android控制項滑動

發布時間: 2023-05-16 09:26:51

⑴ android中可以滑動的控制項式什麼

在使用ScrollView和ListView這樣的控制項的時候,默認在右手邊上是有鏈褲一個滑動的控制項的。在我們用手棚納簡指滑動的時候,顯示出茄吵來這個控制項會不那麼舒服,影響用戶體驗度。這里就是來說明一下,怎麼樣不顯示滑動控制項。

⑵ 在android程序裡面,怎麼讓一個控制項動起來呢

啟一個線程,調用setprogress()的時候用Thread.sleep控制時間,平滑移動的距離和速度需要你自己邏輯控制。
run()方盯友山法中設定一個while(flag)循環,flag=true,凱中初始化progressbar的最大值,然後progressbar.getprogress()獲得當前進度,把這個值賦給一個int變數,再調用setprogress(int)方告飢法設置進度,然後int變數自加,Thread.sleep控制好時間,在按鈕的setOnClickListener中啟動線程。需要停止的進度加一個判斷,將flag變為false就可以了。

⑶ 安卓初學:有大段多行文本要在控制項中顯示,如何讓它能有滾動或滑動顯示全部文本

1.先進入散山Graphical Layout的可視化界面,
在窗體上放上scrollView1,並拉到最右下角,使很數埋大區域,
再在它的內部放上其它控制項如 textView1,如果已經存在的
控制項,就是剪切粘貼到它的內部,在Outline子窗體內就會
看到textView1在scrollView1的下一層;沖畢中
2.再在scrollView1內,設好滾動條參數;
當把大段多行文本用程序送到textView1後,就可滑動看到
整個文本段。

⑷ android滑動拼圖驗證碼控制項

package com.yolanda.code.library.widget;

import android.animation.ValueAnimator;

import android.content.Context;

import android.graphics.Bitmap;

import android.os.Handler;

import android.util.AttributeSet;

import android.view.View;

import android.view.ViewGroup;

import android.view.animation.AlphaAnimation;

import android.view.animation.Animation;

import android.view.animation.LinearInterpolator;

import android.view.animation.TranslateAnimation;

import android.widget.FrameLayout;

import android.widget.ImageView;

import android.widget.SeekBar;

import android.widget.TextView;

import com.yolanda.code.library.R;

import com.yolanda.code.library.view.DiyStyleTextView;

/**

* @author Created by Yolanda on 2018/10/31.

* @description 滑動拼圖驗證碼

*/

public final class DragImageView extends FrameLayout implements SeekBar.OnSeekBarChangeListener {

    private final int showTipsTime = 1500;

    private final int animeTime = 333;

    private final int flashTime = 800;

    private ImageView ivCover;

   州拿 private ImageView ivBlock;

    private SeekBar sb;

    private TextView tvTips2;

    private DiyStyleTextView tvTips;

    private View vFlash, flContent;

    private Handler handler = new Handler();

   物悶 private Bitmap cover, block, completeCover;

    private boolean isNormal;

    public DragImageView(Context context) {

        super(context);

        init();

    }

    public DragImageView(Context context, AttributeSet attrs) {

 罩跡彎       super(context, attrs);

        init();

    }

    public DragImageView(Context context, AttributeSet attrs, int defStyle) {

        super(context, attrs, defStyle);

        init();

    }

    private void init() {

        View.inflate(getContext(), R.layout.drag_view, this);

        flContent = findViewById(R.id.drag_fl_content);

        ivCover = findViewById(R.id.drag_iv_cover);

        ivBlock = findViewById(R.id.drag_iv_block);

        tvTips = findViewById(R.id.drag_tv_tips);

        tvTips2 = findViewById(R.id.drag_tv_tips2);

        vFlash = findViewById(R.id.drag_v_flash);

        tvTips.setColorRegex("拼圖|成功|失敗|正確|[\\d\\.%]+", 0xfff75151);

        sb = findViewById(R.id.drag_sb);

        sb.setMax(getContext().getResources().getDisplayMetrics().widthPixels);

        sb.setOnSeekBarChangeListener(this);

        reset();

    }

    /**

    * 設置資源

    *

    * @param cover        拼圖

    * @param block        滑塊

    * @param completeCover 完成的拼圖

    * @param block_y      滑塊Y值比例

    */

    public void setUp(Bitmap cover, Bitmap block, Bitmap completeCover, float block_y) {

        this.cover = cover;

        this.block = block;

        this.completeCover = completeCover;

        ivCover.setImageBitmap(completeCover);

        ivBlock.setImageBitmap(block);

        setLocation(1f * cover.getWidth() / cover.getHeight(), 1f * block.getHeight() / cover.getHeight(), block_y);

    }

    /**

    * 設置比例大小

    *

    * @param cover_wph  圖片bili

    * @param block_size 滑塊大小占高比

    * @param block_y    滑塊位置占高比

    */

    private void setLocation(final float cover_wph, final float block_size, final float block_y) {

        post(new Runnable() {

            @Override

            public void run() {

                final int w = flContent.getMeasuredWidth();

                int h = (int) (w / cover_wph);

                ViewGroup.LayoutParams l = flContent.getLayoutParams();

                l.width = w;

                l.height = h;

                flContent.setLayoutParams(l);

                ViewGroup.MarginLayoutParams l2 = (MarginLayoutParams) ivBlock.getLayoutParams();

                l2.height = (int) (h * block_size);

                l2.width = l2.height * block.getWidth() / block.getHeight();

                l2.topMargin = (int) (h * block_y);

                ivBlock.setLayoutParams(l2);

            }

        });

    }

    public void ok() {

        ivCover.setImageBitmap(completeCover);

        blockHideAnime();

        int penset = (int) (99 - (timeUse > 1 ? timeUse - 1 : 0) / 0.1f);

        if (penset < 1) penset = 1;

        tvTips.setText(String.format("拼圖成功: 耗時%.1f秒,打敗了%d%%的用戶!", timeUse, penset));

        tipsShowAnime(true);

        flashShowAnime();

        sb.setEnabled(false);

    }

    public void fail() {

        twinkleImage(ivBlock);

        tvTips.setText("拼圖失敗: 請重新拖曳滑塊到正確的位置!");

        tipsShowAnime(true);

        handler.postDelayed(resetRun, showTipsTime);

        sb.setEnabled(false);

    }

    public void reset() {

        final int position = sb.getProgress();

        if (position != 0) {

            ValueAnimator animator = ValueAnimator.ofFloat(1f, 0);

            animator.setDuration(animeTime).start();

            animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                @Override

                public void onAnimationUpdate(ValueAnimator animation) {

                    float f = (Float) animation.getAnimatedValue();

                    sb.setProgress((int) (position * f));

                }

            });

        }

        tipsShowAnime(false);

        tips2ShowAnime(true);

        sb.setEnabled(true);

        ivBlock.setVisibility(GONE);

        vFlash.setVisibility(GONE);

        ivCover.setImageBitmap(completeCover);

        isNormal = true;

    }

    //===================seekbar監聽===================

    private long timeTemp;

    private float timeUse;

    @Override

    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

        int cw = ivCover.getMeasuredWidth();

        int bw = ivBlock.getMeasuredWidth();

        ViewGroup.MarginLayoutParams l = (MarginLayoutParams) ivBlock.getLayoutParams();

        l.leftMargin = (cw - bw) * progress / seekBar.getMax();

        ivBlock.setLayoutParams(l);

    }

    @Override

    public void onStartTrackingTouch(SeekBar seekBar) {

        ivBlock.setVisibility(VISIBLE);

        ivCover.setImageBitmap(cover);

        tips2ShowAnime(false);

        timeTemp = System.currentTimeMillis();

        isNormal = false;

    }

    @Override

    public void onStopTrackingTouch(SeekBar seekBar) {

        timeUse = (System.currentTimeMillis() - timeTemp) / 1000.f;

        if (dragListenner != null)

            dragListenner.onDrag(seekBar.getProgress() * 1f / seekBar.getMax());

    }

    //===================seekbar監聽===================

    //閃爍滑塊

    private void twinkleImage(final View view) {

        ValueAnimator animator = ValueAnimator.ofFloat(0, 1.0F);

        animator.setTarget(view);

        animator.setInterpolator(new LinearInterpolator());

        animator.setDuration(showTipsTime).start();

        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            @Override

            public void onAnimationUpdate(ValueAnimator animation) {

                float f = (Float) animation.getAnimatedValue();

                int time = (int) (showTipsTime * f);

                if (time < 125)

                    view.setVisibility(INVISIBLE);

                else if (time < 250)

                    view.setVisibility(VISIBLE);

                else if (time < 375)

                    view.setVisibility(INVISIBLE);

                else

                    view.setVisibility(VISIBLE);

            }

        });

    }

    //提示文本顯示隱藏

    private void tipsShowAnime(boolean isShow) {

        if ((tvTips.getVisibility() == VISIBLE) == isShow)

            return;

        TranslateAnimation translateAnimation = new TranslateAnimation(

                Animation.RELATIVE_TO_SELF, 0f,

                Animation.RELATIVE_TO_SELF, 0f,

                Animation.RELATIVE_TO_SELF, isShow ? 1f : 0f,

                Animation.RELATIVE_TO_SELF, isShow ? 0f : 1f);

        translateAnimation.setDuration(animeTime);

        //translateAnimation.setInterpolator(new LinearInterpolator());

        tvTips.setAnimation(translateAnimation);

        tvTips.setVisibility(isShow ? VISIBLE : GONE);

    }

    //提示文本顯示隱藏

    private void tips2ShowAnime(boolean isShow) {

        if ((tvTips2.getVisibility() == VISIBLE) == isShow)

            return;

        AlphaAnimation translateAnimation = new AlphaAnimation(isShow ? 0 : 1, isShow ? 1 : 0);

        translateAnimation.setDuration(animeTime);

        //translateAnimation.setInterpolator(new LinearInterpolator());

        tvTips2.setAnimation(translateAnimation);

        tvTips2.setVisibility(isShow ? VISIBLE : GONE);

    }

    //成功完成拼圖滑塊消失

    private void blockHideAnime() {

        AlphaAnimation translateAnimation = new AlphaAnimation(1, 0);

        translateAnimation.setDuration(animeTime);

        //translateAnimation.setInterpolator(new LinearInterpolator());

        ivBlock.setAnimation(translateAnimation);

        ivBlock.setVisibility(GONE);

    }

    //失敗震動動畫

    private void failAnime() {

    }

    //成功高亮動畫

    private void flashShowAnime() {

        TranslateAnimation translateAnimation = new TranslateAnimation(

                Animation.RELATIVE_TO_SELF, 1f,

                Animation.RELATIVE_TO_SELF, -1f,

                Animation.RELATIVE_TO_SELF, 0f,

                Animation.RELATIVE_TO_SELF, 0f);

        translateAnimation.setDuration(flashTime);

        //translateAnimation.setInterpolator(new LinearInterpolator());

        vFlash.setAnimation(translateAnimation);

        vFlash.setVisibility(VISIBLE);

        translateAnimation.setAnimationListener(new Animation.AnimationListener() {

            @Override

            public void onAnimationStart(Animation animation) {

            }

            @Override

            public void onAnimationEnd(Animation animation) {

                vFlash.setVisibility(GONE);

            }

            @Override

            public void onAnimationRepeat(Animation animation) {

            }

        });

    }

    //失敗延時重置控制項

    private Runnable resetRun = new Runnable() {

        @Override

        public void run() {

            tipsShowAnime(false);

            tips2ShowAnime(true);

            sb.setEnabled(true);

            final int position = sb.getProgress();

            ValueAnimator animator = ValueAnimator.ofFloat(1f, 0);

            animator.setDuration(animeTime).start();

            animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                @Override

                public void onAnimationUpdate(ValueAnimator animation) {

                    float f = (Float) animation.getAnimatedValue();

                    sb.setProgress((int) (position * f));

                }

            });

            isNormal = true;

        }

    };

    //監聽

    private DragListenner dragListenner;

    public interface DragListenner {

        void onDrag(float position);

    }

    public void setDragListenner(DragListenner dragListenner) {

        this.dragListenner = dragListenner;

    }

}

⑸ Android怎麼設置界面控制項滑動,如圖

viewpager+fragment+gridview就能實現。
你可以上這里下瞎局腔載源碼,看看人臘凱家怎麼寫,也可磨衫以用第三方jar,幾行代碼就搞定這種效果。
https://github.com/LZLuzhuo/Case/tree/master/HomePageA

⑹ android像下圖中的滑動效果的是什麼控制項做的

viewpager,下面是android滑動的效果圖,

來自於android學習手冊,android學習手冊包含9個章節,108個例態陵州子,源碼文檔隨便看,例子都是可交互,可運行, 源碼採用帆蔽android studio目錄結構,高亮顯示代碼,文檔都採用文檔結構圖顯示,可以快速定位。360手機助手中汪寬下載,圖標上有貝殼

⑺ android 控制項移動方法

Android控制項位置都是自己設置的。
如果要控制項放到任意位置,建議用RelativeLayout(相對布局)
然後給控制項添加屬性,把控制項放到想要的位置
下面是相對布局中 控制項能用到的屬性。
屬性值為true可false
android:layout_centerHrizontal 水平居中
android:layout_centerVertical 垂直居中
android:layout_centerInparent 相對於父元素完全居中
android:layout_alignParentBottom 貼緊父元素的下邊緣
android:layout_alignParentLeft 貼緊父元素的左邊緣
android:layout_alignParentRight 貼緊父元素的右邊緣
android:layout_alignParentTop 貼緊父元素的上邊緣
屬性值必須為id的引用名
android:layout_below 在某元素的下方
android:layout_above 在某元素的上方
android:layout_toLeftOf 在某元素的左邊
android:layout_toRightOf 在某元素的右邊
android:layout_alignTop 本元素的上邊緣和某元素的上邊緣對齊
android:layout_alignLeft 本元素的左邊緣和某元素的左邊緣對齊
android:layout_alignBottom 本元素的下邊緣和某元素下邊緣對齊
android:layout_alignRight 本元素的右邊緣和某元素右邊緣對齊
屬性值為具體的像素值班,如30dp
android:layout_marginBottom 離某元素底邊緣的距離
android:layout_marginLeft 離某元素左邊緣的的距離
android:layout_marginRight 離某元素的右邊緣的距離
android:layout_marginTop 離某元素上邊緣的距離

⑻ Android Seekbar控制項,調用setMax後,seekbar滑動塊無法滑動

你宏賣第一處的參數是不是應蔽襪逗該是: (int) ( ( endValue - startValue ) / stepValue)

要不然(endValue - startValue / stepValue) 是什麼意思呢好正?

⑼ Android中WebView和父控制項滑動沖突

問題場景 在項目的App中有一個ViewPager,它內部包含了WebView,而內部的webview載入了一個可以左右滑動的網頁。當我們在網頁滑動的時候,會直接切換到下一個WebView的頁面,而不是優先響應WebView的滑動,這樣一來WebView和ViewPager的滑動就出現了沖突。

但是產品期望場景是當手指落到WebView的可滑動區域是相應WebView的滑動事件,當滑動到邊緣之後再相應ViewPager的滑動事件。

有了以上思路我們就能著手實現了,但是我們怎麼能檢測到WebView的滑動事件完成了呢?原來WebView的實現者也考慮到了這方面的需求,它暴露了一個方法

官方文檔描述如下圖:

通過上述方法我能就能監測到WebView滑動到了邊界,接下來就是對攔截事件的處理了:

通過上述處理就能完美解決開篇的問題。

熱點內容
和平精英安卓版怎麼調成中文 發布:2025-02-13 22:16:10 瀏覽:36
混沌起源需要什麼配置玩 發布:2025-02-13 22:14:33 瀏覽:277
vs引入文件夾 發布:2025-02-13 22:05:52 瀏覽:127
安卓手機如何調無限電量 發布:2025-02-13 22:05:50 瀏覽:113
phppost長度 發布:2025-02-13 22:05:45 瀏覽:626
烈火戰神源碼 發布:2025-02-13 22:04:51 瀏覽:619
源碼貓交易 發布:2025-02-13 22:04:49 瀏覽:756
廣告腳本鏡頭 發布:2025-02-13 22:04:48 瀏覽:986
安卓手機哪個app自拍更真實 發布:2025-02-13 22:00:19 瀏覽:194
安卓系統密碼忘了怎麼辦 發布:2025-02-13 21:49:28 瀏覽:972