2012-07-12 65 views
3
<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> 

這是我的xml文件。其中可惜的是簡單得多。我的目的是爲了提高動態滾動視圖的高度和圖像(這是滾動視圖)視圖將gradually.so顯示我怎麼能做到這一點,什麼是rootLayout這裏,我怎麼叫rootLayout從我的代碼?什麼是XML中的根佈局?

final Timer timer = new Timer(); 
     timer.scheduleAtFixedRate(new TimerTask() { 
      public void run() { 

       runOnUiThread(new Runnable() 
       { 
        public void run() { 

         secondCounter++; 
         yourNewHeight += 10; 

         sv.getLayoutParams().height = yourNewHeight; 

         LinearLayout root = (LinearLayout)  findViewById(R.id.rootLayout); 
         root.invalidate(); 
         Log.v("", "" +sv.getLayoutParams().height); 

         if(secondCounter == 20){ 
          timer.cancel(); 
         } 
        } 
       }); 
      } 
     }, delay, period); 

這是我在java文件中的代碼,但它不工作。夥計們,你能幫我解決.. !!!

+1

請注意,'AbsoluteLayout'早已貶值,你應該使用的替代品。 – Trevor 2012-07-12 10:39:58

+1

使用相對佈局相反,你不必增加gridview給它包裝內容,你必須動態添加圖像線性佈局,這將在scrollview – AkashG 2012-07-12 10:46:21

+0

下謝謝.. :-)但我不能正確放置項目在XMl當我使用線性佈局。 – Amitabha 2012-07-12 10:58:21

回答

0

此佈局的根是AbsoluteLayout

可以得到使用電話就像你Activity參考,這根View連同其所有子:

mRootView = ((ViewGroup)findViewById(R.id.rootLayout)); 

注意AbsoluteLaoyut早已貶值,你可能會想用一個來代替它替代ViewGroup,如LinearLayoutRelativeLayout等,這取決於你的佈局的其餘部分,如何你想要做的事情。

+0

因爲我在這個領域是新的,所以我覺得容易AbsoluteLayout。我在LinearLayout或RelativeLayout中遇到的問題是,我無法將項目放置在XMl中的適當位置。所以我正在使用它。有什麼解決方案Trevor先生? – Amitabha 2012-07-12 10:55:42

0

如果你誇大你的XML適當的代碼(即所謂的setContentView()),你應該能夠使用rootLayout參考:

AbsoluteLayout root = (AbsoluteLayout) findViewById(R.id.rootLayout); 

但如果你只是想增加ScrollView的高度,它更有意義,直接撥打:

ScrollView scroll = (ScrollView) findViewById(R.id.scrollView1); 

和上面一樣,你應該使用RelativeLayoutLinearLayout而非AbsoluteLayout

0

由於滾動型只能在它有一個孩子,你可以使用滾動型本身作爲你的根元素具有的LinearLayout作爲直接和唯一的孩子吧,在其內部ü可以添加你想要的任何意見。

而且AbsoluteLayout已被棄用,我建議你不要使用它