2012-08-01 102 views
0

我目前有一個在android佈局的標籤內的可滾動視圖的問題。如下所示,該視圖在選項卡布局中沒有實現可滾動視圖的情況下滾動瀏覽。在標籤佈局內的Android可滾動視圖

http://i46.tinypic.com/2ccmp0w.png

當我把選項卡式佈局內可滾動視圖它顯示了出現車和不可用的一個小的可滾動視圖。如下所示。

http://tinypic.com/r/29ej2ft/6

用於選項卡主機的代碼是下面

<?xml version="1.0" encoding="utf-8"?> 
<TabHost 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@android:id/tabhost" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<RelativeLayout 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent"> 
    <FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_alignParentTop="true" 
     android:padding="5dp" /> 
    <TabWidget 
     android:id="@android:id/tabs" 
     android:layout_alignParentBottom="true" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" />   
</RelativeLayout> 
</TabHost> 

並且這是用於與滾動視圖的選項卡中的代碼來實現

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/todayScroll" 
android:layout_height="wrap_content" 
android:layout_width="fill_parent" > 

<LinearLayout 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent"  
    android:orientation="vertical" > 

      <ExpandableListView 
       android:id="@+id/ExpList" 
       android:layout_height="match_parent" 
       android:layout_width="match_parent" 
       android:groupIndicator="@null" /> 

</LinearLayout> 
</ScrollView> 

如何任何想法得到的內容滾動正確,而不是在選項卡的方式將不勝感激:)謝謝。

我已經嘗試了公平的幾次,但它開始變得非常沮喪。編輯: 這裏是TabHostActivity文件。

public class TabbedMainActivity extends TabActivity { 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.tab_main); 

    TabHost tabHost = getTabHost(); 

    // Tab for todays meals 
    TabSpec todaysSpec = tabHost.newTabSpec("Todays"); 
    //you could set icon here as well as title 
    todaysSpec.setIndicator("Todays"); 
    Intent todaysIntent = new Intent(this, TodaysMealsActivity.class); 
    todaysSpec.setContent(todaysIntent); 

    // Tab for future meals 
    TabSpec futureSpec = tabHost.newTabSpec("Future"); 
    futureSpec.setIndicator("Future"); 
    Intent futureIntent = new Intent(this, FutureMealsActivity.class); 
    futureSpec.setContent(futureIntent); 

    // Tab for comments 
    TabSpec commentsSpec = tabHost.newTabSpec("Comments"); 
    commentsSpec.setIndicator("Feedback"); 
    Intent commentsIntent = new Intent(this, CommentsActivity.class); 
    commentsSpec.setContent(commentsIntent); 

    // Adding all TabSpec to TabHost 
    tabHost.addTab(todaysSpec); // Adding todays tab 
    tabHost.addTab(futureSpec); // Adding future tab 
    tabHost.addTab(commentsSpec); // Adding comments tab 
} 
} 

乾杯, Rmplanner

+0

爲什麼你保持一個ListView滾動型內的LinearLayout內。爲什麼不能使用listview或listactivity? – san 2012-08-01 03:25:04

回答

0

從評論編輯:另一種解決方案(一個由OP使用)被發現here

在您的ScrollView上使用android:layout_height="fill_parent"。 (或者,因爲fill_parent已過時,使用android:layout_height="match_parent"。)

首先,刪除您ScrollView,以及與此更換你的RelativeLayout

<RelativeLayout 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent"> 

    <FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_above="@android:id/tabs" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:padding="5dp" /> 

    <TabWidget 
     android:id="@android:id/tabs" 
     android:layout_alignParentBottom="true" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 

</RelativeLayout> 
+0

嗨,感謝您的快速回復,但不幸的是,這並沒有解決這個問題。滾動視圖仍然很小,無法填充和匹配父項。 – rmplanner 2012-08-01 02:02:48

+0

你可以編輯你的OP,以顯示你如何在你的標籤中包含'ScrollView'?看起來有可能的是,包含ScrollView的任何東西都使用'wrap_content'。 – Eric 2012-08-01 02:04:18

+0

因爲我對android非常陌生,所以我不確定你的問題,但是我可以從你的問題中收集的是你要求標籤主機的活動。如果是這樣 - 我現在編輯它;如果不是,請澄清,如果你想要更多的信息。 – rmplanner 2012-08-01 02:14:50