什么是android的等效代码:layout_above =“@ android:id / tabs”?

时间:2010-11-19 21:21:31

标签: android layout tabs frame

我创建了一个TabWidget

TabWidget tabWidget = new TabWidget(this);
        tabWidget.setId(android.R.id.tabs);

和FrameLayout

FrameLayout frameLayout = new FrameLayout(this);
        frameLayout.setId(android.R.id.tabcontent);

如何在选项卡上方制作framelayout?

**what is the equivalent code to "android:layout_above="@android:id/tabs"**

修改

我正在使用此代码,这是正确的吗?

TabHost tabHost = new TabHost(this);
tabHost.setLayoutParams(
                new RelativeLayout.LayoutParams(
                        LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT,1));
 TabWidget tabWidget = new TabWidget(this);
        tabWidget.setId(android.R.id.tabs);

RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(width, height);
lp.addRule(RelativeLayout.ABOVE, R.id.tabcontent);
tabWidget.setLayoutParams(lp);

tabHost.addView(tabWidget);
FrameLayout frameLayout = new FrameLayout(this);
        frameLayout.setId(android.R.id.tabcontent);
        frameLayout.setPadding(0, 55, 0, 0);
tabHost.addView(frameLayout, new RelativeLayout.LayoutParams(
                  LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 
tabHost.setup();

1 个答案:

答案 0 :(得分:5)

RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(width, height);
lp.addRule(RelativeLayout.ABOVE, R.id.tabcontent);
tabWidget.setLayoutParams(lp);