1
SeekBar
值從0開始到100%。我想顯示的圖像取決於seekbar百分比。如果seekbar
達到10%,我想顯示10%的圖像長度。如果seekbar達到50%,我想顯示一半的圖像。同樣,我想顯示的圖像取決於seekbar
值。如何實現這一目標?要隱藏和顯示圖像取決於seekbar的值
SeekBar
值從0開始到100%。我想顯示的圖像取決於seekbar百分比。如果seekbar
達到10%,我想顯示10%的圖像長度。如果seekbar達到50%,我想顯示一半的圖像。同樣,我想顯示的圖像取決於seekbar
值。如何實現這一目標?要隱藏和顯示圖像取決於seekbar的值
使用佈局作爲容器與orientation =「horizontal」,把你的圖像內,並把一個無效的ImageView。然後調整圖像的重量和無效圖像,以便重新顯示搜索欄百分比。
的XML:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imageViewYourImage"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="40"
android:src="..." />
<ImageView
android:id="@+id/imageViewVoidImage"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="20" />
</LinearLayout>
,代碼:
int percentage = 10;
int max = 100;
imageViewVoidImage.setLayoutParams(
new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, (int) (max * 10f - percentage * 10f)));
imageViewYourImage.setLayoutParams(
new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, (int) (percentage * 10f)));
感謝ü..我會嘗試這個。 –
我也加了java代碼! –
@Seraphim先生我們可以在seekbar onStartTrackingTouch上設置imageview的值,並提供觸摸.... – rajshree