2013-05-02 33 views
0

對於我正在處理的應用程序,我希望有3個選項卡,其中包含不同的元素。 我試圖尋找一種方法來實現這一點,但我似乎無法找到我需要的例子。在一個選項卡內設置多個項目關閉Android的Tabhost

Basicly我想這樣的:

標籤1,包含4個按鈕和一個TextView

標籤2,包含一個可滾動的ImageView

標籤3,包含網頁視圖

我想無需使用活動即可解決此問題,因爲所有3個選項卡都需要訪問相同的數據。

目前我使用此XML作爲佈局:

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+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"> 
    <TabWidget 
     android:id="@android:id/tabs" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 
    <FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:id="@+id/photoLayout"> 
      <Button 
       android:text="@string/photoButton" 
       android:layout_column="0" 
       android:id="@+id/photoButton" 
       android:textSize="10dp" /> 
      <Button 
       android:text="@string/locateButton" 
       android:layout_column="1" 
       android:id="@+id/locateButton" 
       android:textSize="10dp" /> 
      <Button 
       android:text="@string/cropButton" 
       android:layout_column="2" 
       android:id="@+id/cropButton" 
       android:textSize="10dp" /> 
      <Button 
       android:text="reset" 
       android:layout_column="3" 
       android:id="@+id/resetButton" 
       android:textSize="10dp" /> 
      <ScrollView 
       android:minWidth="25px" 
       android:minHeight="25px" 
       android:layout_width="fill_parent" 
       android:layout_height="370dp" 
       android:id="@+id/scrollView1" 
       android:fillViewport="true"> 
       <TextView 
        android:text="Text" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:id="@+id/textView1" /> 
      </ScrollView> 
     </LinearLayout> 
     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:id="@+id/webviewLayout"> 
      <WebView 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:id="@+id/webView1" /> 
     </LinearLayout> 
     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:id="@+id/imageLayout"> 
      <ScrollView 
       android:minWidth="25px" 
       android:minHeight="25px" 
       android:layout_width="fill_parent" 
       android:layout_height="412dp" 
       android:id="@+id/scrollView2" 
       android:fillViewport="true"> 
       <ImageView 
        android:src="@android:drawable/ic_menu_gallery" 
        android:layout_column="0" 
        android:id="@+id/imageView1" 
        android:layout_height="411.6dp" 
        android:layout_width="316.7dp" 
        android:scaleType="centerInside" /> 
      </ScrollView> 
     </LinearLayout> 
    </FrameLayout> 
</LinearLayout> 

這樣做的問題是,我得到一個運行時異常說:

Java.Lang.RuntimeException: Binary XML file line #1: You must supply a layout_width attribute.

任何有助於解決這個問題將不勝感激!

回答

1

要回答拋出的異常,你需要在你聲明的每一個元素中指定layout_width和layout_height,在你的情況下,你沒有在這些按鈕上指定任何元素。但是爲了表達我的好奇心,我相信你應該在單獨的活動和單獨的佈局中做到這一點,「相同的數據」總是可以通過使用一些我相信的附加內容來傳遞。

+0

嗯我可以發誓我昨天試過,但可能不是..因爲當我第二次嘗試它時,它的工作,所以謝謝你! – jHogen 2013-05-02 10:16:42

+0

沒問題,很高興我幫了忙 – 2013-05-02 12:12:14

相關問題