2012-07-13 60 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