我正在用自定義的拇指創建一個seekbar。所以我的拇指它layeredDrawable。所以我想在拖動拇指的同時調整我的拇指圖像。Seekbar的拇指動畫拖動
我的意思是,當我拖動我的拇指...拇指大小將增加,並且seekbar位置不應該改變。
請幫助我,並提前致謝。
我正在用自定義的拇指創建一個seekbar。所以我的拇指它layeredDrawable。所以我想在拖動拇指的同時調整我的拇指圖像。Seekbar的拇指動畫拖動
我的意思是,當我拖動我的拇指...拇指大小將增加,並且seekbar位置不應該改變。
請幫助我,並提前致謝。
更改搜索欄拇指大小,你滑動需要一些代碼
android:thumb="@drawable/round"
代碼
private SeekBar seekBar;
在OnCreate
添加
seekBar = (SeekBar) findViewById(R.id.mySeekBarID);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
int progress = 0;
@Override
public void onProgressChanged(SeekBar seekBar, int progresValue, boolean fromUser) {
progress = progresValue;
Resources res = getResources();
Drawable thumb = res.getDrawable(R.drawable.round);
int h = progress/10;
int w = h;
Bitmap bmpOrg = ((BitmapDrawable) thumb).getBitmap();
Bitmap bmpScaled = Bitmap.createScaledBitmap(bmpOrg, w, h, true);
Drawable newThumb = new BitmapDrawable(res, bmpScaled);
newThumb.setBounds(0, 0, newThumb.getIntrinsicWidth(), newThumb.getIntrinsicHeight());
seekBar.setThumb(newThumb);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
測試和按預期工作。即當你移動拇指時,它會變得越來越小,向左變大,向右變大
這條線在這裏int h = progress/10
;``當你滑動時計算新的拇指大小,所以你需要玩一些數學來獲得你需要的確切結果
使用選擇的搜索條拇指像這樣的
thumb.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/thumb_small" android:state_enabled="false"/>
<item android:drawable="@drawable/thumb_big" android:state_pressed="true"/>
<item android:drawable="@drawable/thumb_small" android:state_selected="true"/>
<item android:drawable="@drawable/thumb_small"/>
</selector>
,並在你的搜索條參考這個類似這樣的佈局file.xml
<SeekBar
android:id="@+id/seekBarRadius"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="false"
android:max="100"
android:maxHeight="10dp"
android:minHeight="10dp"
android:progress="100"
android:thumb="@drawable/thumb" />
thumb_big.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="20dp" />
<solid android:color="#FF049BFF" />
<size
android:width="40dp"
android:height="40dp" />
</shape>
</item>
thumb_small.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="15dp" />
<solid android:color="#FF049BFF" />
<size
android:width="30dp"
android:height="30dp" />
</shape>
</item>
所以基本上你有一個圖像,你想在移動seekbar時重新調整它的大小? – Tasos
是@Tasos我正在找:) :) – Newts
@Newts是我的回答有幫助 –