第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

SwipeGestureDetector 將圖像從 int [] 更改為 Imageview

SwipeGestureDetector 將圖像從 int [] 更改為 Imageview

富國(guó)滬深 2022-07-20 20:16:05
當(dāng)我從下到上和從上到下滑動(dòng)時(shí),我需要從 int Array 中獲取圖像,然后在 Imageview 中顯示。GestureDetector 運(yùn)行良好,但我想從 int [] 中獲取圖像,然后在滑動(dòng)時(shí)放入 Imageview 中。例子 :int [] imageBank = new int[] {            R.drawable.image0,            R.drawable.image1,            R.drawable.image2,            R.drawable.image3,            R.drawable.image4, }; 從上到下滑動(dòng),從 [ ] 中獲取圖像 0,在 Imageview 中顯示從上到下滑動(dòng),從 [ ] 中獲取圖像 1,在 Imageview 中顯示從下往上滑動(dòng),從 [ ] 中獲取圖像 0,在 Imageview 中顯示從下往上滑動(dòng),從 [ ] 中獲取圖像 4,在 Imageview 中顯示完成 MainActivityimport android.support.constraint.ConstraintLayout;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.MotionEvent;import android.widget.Button;import android.widget.ImageView;import android.widget.Toast;import driss.moodtracker.R;import driss.moodtracker.component.SwipeGestureDetector;public class MainActivity extends AppCompatActivity {private SwipeGestureDetector gestureDetector;@Overrideprotected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_main);    gestureDetector = new SwipeGestureDetector(this);    Button button_comment = (Button) findViewById(R.id.button1);    Button button_calendar = (Button) findViewById(R.id.button2);}@Overridepublic boolean dispatchTouchEvent(MotionEvent event) {    return gestureDetector.onTouchEvent(event);}public void onSwipe(SwipeGestureDetector.SwipeDirection direction) {    ImageView imagePic = (ImageView) findViewById(R.id.imageview);    ConstraintLayout currentLayout = (ConstraintLayout) findViewById(R.id.main_layout);    // ARRAY OF SMILEYS LIST    int [] arraySmileys = new int[] {            R.drawable.smiley_super_happy,            R.drawable.smiley_happy,            R.drawable.smiley_normal,            R.drawable.smiley_disappointed,            R.drawable.smiley_sad,    };
查看完整描述

2 回答

?
浮云間

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超4個(gè)贊

最好使用ViewPageror RecyclerViewwith ViewPager-like行為而不是GestureDetector



查看完整回答
反對(duì) 回復(fù) 2022-07-20
?
月關(guān)寶盒

TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超5個(gè)贊

定義一個(gè)“計(jì)數(shù)器”(整數(shù)變量)來(lái)存儲(chǔ)整數(shù)數(shù)組的索引?,F(xiàn)在基于檢測(cè)到的滑動(dòng),如果用戶從底部向上滑動(dòng),則增加計(jì)數(shù)器并將索引項(xiàng)的圖像設(shè)置為您的圖像視圖,反之亦然。


示例代碼:


int counter = 0;


public void swipe() {

    switch (direction) {

    case LEFT_TO_RIGHT:

        message = "Left to right swipe";

        break;


    case RIGHT_TO_LEFT:

        message = "Right to left swipe";

        break;


    case TOP_TO_BOTTOM:

        if(counter > 0) {

            counter--;

            imagePic.setImageResource(arraySmileys[counter]);

        }

        break;


    case BOTTOM_TO_TOP:

        if(counter < arraySmileys.length()) {

            counter++;

            imagePic.setImageResource(arraySmileys[counter]);

        }

        break;

   }

}


查看完整回答
反對(duì) 回復(fù) 2022-07-20
  • 2 回答
  • 0 關(guān)注
  • 105 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)