1

SeekBar値は 0 から 100 % までです。シークバーの割合に応じて画像を表示したい。seekbar10% に達したら、画像の長さの 10% を表示したい。シークバーが 50% に達した場合、画像の半分を表示したい。同様に、画像が値に依存することを示したいと思いseekbarます。これを達成する方法は?

4

1 に答える 1

1

orientation="horizo​​ntal" のコンテナーとしてレイアウトを使用し、画像を内部に配置し、void ImageView も配置します。次に、イメージと void イメージのウェイトを調整して、シークバーの割合を再現できるようにします。

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)));
于 2013-07-03T11:28:58.313 に答える