【发布时间】:2012-07-13 06:43:26
【问题描述】:
是否有任何过程在运行时逐渐增加 ScrollView 的高度。我的意图是逐渐显示 ScrollView 内的图像。所以我想增加 ScrollView 的高度。有什么办法可以完成我的工作吗??请帮帮我。我的 XmlFile 的内容是:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rootLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:scrollbars="none"
android:layout_x="0dp"
android:layout_y="0dp"
android:fillViewport="true" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="0dp"
android:layout_y="0dp"
android:src="@drawable/background" />
</LinearLayout>
</ScrollView>
</LinearLayout>
我的代码是:
final Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
runOnUiThread(new Runnable()
{
public void run() {
secondCounter++;
yourNewHeight += 10;
// sv is object of scroll view
sv.getLayoutParams().height = yourNewHeight;
root.invalidate(); // root is rootview
if(secondCounter == 20){
timer.cancel();
}
}
});
}
}, delay, period);
这是我的屏幕截图:
模糊图像在 Scrollview 中,随着 ScrollView 高度的增加,模糊图像逐渐显示。
【问题讨论】:
-
您是否以编程方式在图像上添加更多内容??
-
没有。滚动视图中只有一张图片。
-
请告诉我你想展示什么。如果只有一张图片而不是你为什么要在滚动视图中添加??
-
在代码中使用
setLayoutParams(..)以编程方式设置宽度和高度。 -
嗯....!!!只有一个图像。我的意图是逐渐增加scrollView的高度,以便可以显示其中的图像..等待我在这里发布一些屏幕截图..!!!
标签: android xml android-imageview android-scrollview