2010-11-04 25 views

回答

4

一個偉大的搜索後,我得到它。我以這種方式放置我的第一個佈局!

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <LinearLayout android:id="@+id/contentViewLayout" 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="@color/white" 
     android:layout_marginBottom="56dip"/> 

     <HorizontalScrollView 
      android:scrollbarSize="2dip" 
      android:layout_alignParentBottom="true" 
      android:layout_width="fill_parent" 
      android:background="@drawable/background" android:layout_height="56dip"> 

    </HorizontalScrollView> 
</RelativeLayout> 

當我在它啓動新的活動我用follwing代碼...

public class MainActivityWithTabbar extends ActivityGroup implements OnClickListener{ 

    public LocalActivityManager activityManager; 
    public LinearLayout contentViewLayout; 
    public LinearLayout.LayoutParams contentViewLayoutParams; 
    private Context context; 
    public Intent nextActivit; 

    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     context = this; 
     activityManager = getLocalActivityManager(); 
     setContentView(R.layout.mainActivityLayout); 
     contentViewLayout = (LinearLayout)findViewById(R.id.contentViewLayout); 
     contentViewLayoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); 

     nextActivit = new Intent(this, NextActivity.class); 
     startGroupActivity("activity1", nextActivit); 

    } 

    public void startGroupActivity(String id, Intent intent) 
    { 
     contentViewLayout.removeAllViews(); 

     View view = activityManager.startActivity(id, intent).getDecorView(); 
     contentViewLayout.addView(view, contentViewLayoutParams); 
    } 
} 

所以它workssss這種情況下....

+0

我就像這個問題一樣卡住看到你的代碼我得到了getLocalActivityManager()如何實現這一點? – 2013-07-03 08:01:40

+0

剛剛在這裏得到同樣的問題.. [這](http://codepad.org/u9DOM6po)是我如何解決它。 – 2013-12-16 11:52:24

0

您是指視圖中包含的活動?你不能那樣做。視圖包含可見元素,活動用於運行程序代碼。

如果您的意思是通過與視圖交互來開始新的活動,就像用戶點擊按鈕一樣,您需要實現一個onClick()方法,並從那裏開始活動。

layout.xml 
... 
android:onClick="onButton" 

MyActivity.java 
... 
public void onButton(View v) { 
    Intent i = new Intent(mCtx, OtherActivity.class); 
    startActivityForResult(i, OPTION); 
} 
+0

在要顯示新活動在我目前的佈局。我不想在我的新活動中使用任何其他佈局。?例如,如果我的第一個活動使用線性佈局,那麼新活動應該以該線性佈局顯示。 – Arslan 2010-11-04 13:12:19

+0

好的,所以你想爲兩個活動使用相同的佈局?在這種情況下,您可以在調用setContentView()時指定相同的資源。 – Robert 2010-11-04 13:37:25

+0

但在這種情況下。佈局將重新繪製(),我必須再次關聯處理程序來回標籤! – Arslan 2010-11-04 13:42:15

相關問題