SeekBar
值从0到100%开始。我想显示图像取决于搜索栏百分比。如果seekbar
达到10%,我想显示10%的图像长度。如果搜索栏达到50%,我想显示一半的图像。同样,我想显示图像取决于seekbar
值。怎么做到这一点?
答案 0 :(得分:1)
将布局用作方向=“水平”的容器,将图像放入其中并放置一个无效的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)));