2011-11-22 101 views
0

我正在使用TabLayout創建應用程序,並且在使用Intents加載不同的類時遇到顯示問題。安卓選項卡意圖,通過選項卡布局剪輯

我嘗試使用方法創造它在這裏看到了Android開發指南解釋

http://developer.android.com/resources/tutorials/views/hello-tabwidget.html

但是我遇到的問題是,我想沿着應用底部的標籤,而不是我已經完成了頂部。問題是屏幕上沒有足夠的空間來查看整個應用程序,所以當我點擊一個新選項卡並加載它的佈局時,它會直接通過選項卡。我嘗試添加ScrollView,但它似乎不工作。

任何建議,如何解決這個問題,所以當我打開一個屏幕,我可以上下滾動我的標籤總是出現在底部,並通過我的標籤沒有我的佈局片段的頁面。

任何幫助,將不勝感激

代碼爲我的main.xml是

<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" android:background="#92c223"> 

<LinearLayout android:orientation="vertical" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:padding="5dp"> 

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

</LinearLayout> 

<TabWidget android:id="@android:id/tabs" 
    android:layout_width="fill_parent" android:layout_height="wrap_content" 
    android:layout_gravity="bottom" /> 
</TabHost> 

而且我以前在java中的標籤之間交換的代碼是

intent = new Intent().setClass(this, tag.class); 
    spec = tabHost.newTabSpec("tag1") 
      .setIndicator("tag1", res.getDrawable(R.drawable.icon)) 
      .setContent(intent); 
    tabHost.addTab(spec); 

    intent = new Intent().setClass(this, tag2.class); 
    spec = tabHost.newTabSpec("tag2") 
      .setIndicator("tag2", res.getDrawable(R.drawable.icon2)) 
      .setContent(intent); 
    tabHost.addTab(spec); 

回答

1

試試這個

<?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"> 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:padding="5dp"> 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:padding="5dp" 
      android:layout_weight="1"/> 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="0"/> 

    </LinearLayout> 

</TabHost> 

所不同的是在的FrameLayout,高度設定爲wrap_content,其中你被設置爲FILL_PARENT。他還在FrameLayout上應用了layout_weight = 1,在TabWidget上應用了layout_weight = 0。

取自here

+0

非常感謝,添加你的代碼,然後添加ScrollLayout它和現在的作品完美。 乾杯:D – AdamM