2013-07-03 23 views
1

SeekBar值從0開始到100%。我想顯示的圖像取決於seekbar百分比。如果seekbar達到10%,我想顯示10%的圖像長度。如果seekbar達到50%,我想顯示一半的圖像。同樣,我想顯示的圖像取決於seekbar值。如何實現這一目標?要隱藏和顯示圖像取決於seekbar的值

回答

1

使用佈局作爲容器與orientation =「horizo​​ntal」,把你的圖像內,並把一個無效的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))); 
+0

感謝ü..我會嘗試這個。 –

+0

我也加了java代碼! –

+0

@Seraphim先生我們可以在seekbar onStartTrackingTouch上設置imageview的值,並提供觸摸.... – rajshree