2011-09-01 108 views
0

你好,可能還有一些女孩,是否可以堆疊佈局對象。那麼一個對象是另一個呢? 我的問題是這樣的,我有一個tabhost,在tabhost下我有一個帶有textview的tablerow。如何將不同的佈局對象堆疊在一起?

我使tabhost選項卡不可見,但它隱藏我的tablrow與textview中,我怎麼能把它帶來盈方?

這裏是Layout.xml

<?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" 
     android:weightSum="1"> 
    <RelativeLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     > 
     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" /> 
     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignBottom = "@android:id/tabcontent" 
      android:visibility="invisible"/> 

     <TableRow 
      android:id="@+id/ADFilterOverview" 
      android:layout_height="wrap_content" 
      android:onClick="onClickADConfig" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentLeft="true" 
      android:layout_alignTop="@android:id/tabs" 
      android:layout_width="match_parent"> 

      <TextView 
       android:text="@string/newadfilter" 
       style="@style/NormalFont" 
       android:layout_gravity="bottom|left"> 
      </TextView> 
     </TableRow> 
    </RelativeLayout> 
</TabHost> 

Thx提前

問候 野生動物園

一些更多的信息,以便更好地理解:

後來我我的活動代碼看起來像這樣:

package de.retowaelchli.filterit; 

    import android.app.TabActivity; 
    import android.os.Bundle; 
    import android.widget.TabHost; 
    import android.content.Intent; 

    public class StatsActivity extends TabActivity { 
     /** Called when the activity is first created. */ 
     @Override 
     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.stats); 
      TabHost tabHost = getTabHost();  

      tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("whatever").setContent(new Intent(this, SFilterStatsActivity.class))); 
      tabHost.setCurrentTab(1); 

     } 

    /** Verweise auf die anderen Seiten **/ 
public void onClickADConfig(View view){ 
    final Intent i = new Intent(this, ADFilterConfigActivity.class); 
    startActivity(i); } 


    } 

從我Tabhost鏈接的類看起來例如像這樣:

package de.retowaelchli.filterit; 

import android.app.ListActivity; 
import android.os.Bundle; 
import android.widget.ArrayAdapter; 


public class ADFilterStatsActivity extends ListActivity { 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mListContent)); 
    } 

    private static String[] mListContent={"Item 1", "Item 2", "Item 3","Item 1", "Item 2", "Item 3","Item 1", "Item 2", "Item 3","Item 1", "Item 2", "Item 3"}; 
} 

所以你看,我買了它一個標籤,這是從我的ListActivity填補了TabHost,該tabhost應該被隱藏(不可見的),在這個隱藏的標籤上應該是可見的表格。所以我可以點擊它來到我的其他班。 我希望這可以幫助你們......

找到了解決辦法THX Egon

這裏是解決

<?xml version="1.0" encoding="utf-8"?> 


<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabcontent" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    > 



     <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:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" /> 
     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignBottom = "@android:id/tabcontent" 
      android:visibility="invisible"/> 
     <TableRow android:layout_height="wrap_content" android:id="@+id/ADFilterOverview" android:layout_width="match_parent" android:onClick="onClickADConfig" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true"> 
      <TextView android:layout_gravity="bottom|left" android:text="@string/newadfilter" style="@style/NormalFont"></TextView> 
     </TableRow> 
     </RelativeLayout> 
     </TabHost> 


    </FrameLayout> 
+0

爲什麼你讓你的TabHost隱形? – user370305

+0

我只有一個Tab,它是全部激活的,並且充滿了從數據庫填充的ListActivity中的內容。我需要Tablerow才能進入下一個活動,在那裏我可以爲我的數據庫設置內容,然後在此Tabhost中展示=)我希望你明白 – safari

+0

,因爲你總是在選項卡上,爲什麼使用TabHost? –

回答

1

如果您使Parentview不可見,那麼其子視圖也會自動隱藏。在這種情況下,您必須爲新標籤定義其他佈局。

如果這不正確,請進行編輯或建議我。 Thanx

編輯:你的xml代碼我認爲tabhost是一個parentview和tablerow,textview是它的childview。

0

我認爲,問題是你設置的tabwidget是alignParentBottom然後您將TableRow設置爲具有tabwidget的aligntop。因此它不可見。讓tabwidget不可見會隱藏它,但佔位符仍然存在。

+0

所以我應該改變,它工作嗎? – safari

2

如果您想要將一個View放置在另一個的Z軸上方,可以使用FrameLayout。它可以讓您在背景上放置一個View,並在其上放置其他視圖。它非常強大且易於使用,所以你必須試一試。希望這可以幫助。

+0

Thx爲您的幫助。我有一個FrameLayout在它,我怎麼能在背景中獲得它? – safari

+0

@safari,放置在FrameLayout內的第一個視圖始終是當然,你可以創建嵌套的佈局來實現你的目標 – Egor

+0

嗯,我仍然試圖做到這一點:(),佈局應該如何? – safari

相關問題