2010-11-04 72 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

相关问题