2012-07-13 59 views
1

是否有任何过程在运行时逐渐增加ScrollView的高度。我的目的是逐步显示ScrollView中的图像,所以我想增加ScrollView的高度。有什么办法可以做我的工作吗?请帮我我XMLFILE的out.Content是:如何在ScrollView中逐渐显示图像?

<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); 

这里是我的屏幕截图:

enter image description here

模糊的图像与Scrollview和ScrollView的高度增加了模糊的图像逐渐显示。

+0

您是否以编程方式在图像上添加多于? – AkashG 2012-07-13 06:53:51

+0

没有。只有一个图像已经在scrollView中使用。 – Amitabha 2012-07-13 06:59:23

+0

请向我清楚你想要显示什么。如果只有一个图像,而不是为什么你在scrollview中添加? – AkashG 2012-07-13 07:02:04

回答

0

我编辑了自己的代码..

<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="fill_parent" 
    android:layout_height="80dp"> 

    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width=" fill_parent" 
     android:layout_height="wrap_content" > 


<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:src="@drawable/background" /> 
    </LinearLayout> 

</ScrollView> 

让我知道这个或不..行已经做了..

+0

nope .. :(我应该发布我的java代码?? – Amitabha 2012-07-13 06:53:48

+0

后ur代码....所以我们可以检查出来.. – 2012-07-13 07:13:54

+0

完成.. !!检查出来..plzzz .. !!! – Amitabha 2012-07-13 07:22:21

0

可以使用setLayoutParams(..)设置你的宽度和高度编程。检查出问题mao给了here和解决方案。

+0

高度滚动视图不会被固定,它会定期增加。 – Amitabha 2012-07-13 07:27:34