首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android和tabactivity

Android和tabactivity
EN

Stack Overflow用户
提问于 2012-07-19 17:06:11
回答 1查看 707关注 0票数 1

我有下面的例子:

当我点击Tab2时,在安卓屏幕开始和Tabs行之间的活动并不适合。为什么?我可以做些什么来试着适应屏幕?

代码语言:javascript
复制
Main.java

public class Tabs_androidActivity extends ActivityGroup {
    public TabHost mTabHost;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    TabHost tabHost=(TabHost)findViewById(R.id.tabHost);
    tabHost.setup(this.getLocalActivityManager());


    TabSpec spec1=tabHost.newTabSpec("Tab 1");
    spec1.setContent(R.id.tab1);
    spec1.setIndicator("Tab 1");

    TabSpec spec2=tabHost.newTabSpec("Tab 2");
    spec2.setIndicator("Tab 2");
    spec2.setContent(new Intent(this, Tab2.class));



    TabSpec spec3=tabHost.newTabSpec("Tab 3");
    spec3.setIndicator("Tab 3");
    spec3.setContent(R.id.tab3);



    tabHost.addTab(spec1);
    tabHost.addTab(spec2);
    tabHost.addTab(spec3);

    tabHost.setCurrentTab(0);

    }

}

代码语言:javascript
复制
Tab2.java
public class Tab2 extends  Activity {

    /** Called when the activity is first created. */ 

    TextView call;
@Override 

 public void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 

    setContentView(R.layout.logs);
  ///....


}
}

和main.xml

代码语言:javascript
复制
<?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" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
         >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true" />

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_alignParentTop="true" >

            <LinearLayout
                android:id="@+id/tab1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >


            </LinearLayout>

            <LinearLayout
                android:id="@+id/tab2"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >


            </LinearLayout>

            <LinearLayout
                android:id="@+id/tab3"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >


            </LinearLayout>


        </FrameLayout>
    </RelativeLayout>

</TabHost>

logs.xml

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TextView
        android:id="@+id/call"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true" >
    </TextView>

</RelativeLayout>
EN

回答 1

Stack Overflow用户

发布于 2012-07-19 17:19:49

main.xml:

代码语言:javascript
复制
<?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">

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
         >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:layout_marginTop="60dp"/>
       <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp"/>
    </RelativeLayout>

</TabHost>

您的选项卡活动:

代码语言:javascript
复制
public class TabActivity extends android.app.TabActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tab_layout);
//  Resources res=getResources();
    TabHost tabHost=getTabHost();
    TabHost.TabSpec spec;
    Intent intent;

    intent=new Intent().setClass(this, Tab1Activity.class);
    spec=tabHost.newTabSpec("tab1").setIndicator(yourimageID).setContent(intent);
    tabHost.addTab(spec);

    intent=new Intent().setClass(this, Tab2Activity.class);
    spec=tabHost.newTabSpec("tab2").setIndicator(yourimageID).setContent(intent);
    tabHost.addTab(spec);

    intent=new Intent().setClass(this, Tab3Activity.class);
    spec=tabHost.newTabSpec("tab3").setIndicator(yourimageID).setContent(intent);
    tabHost.addTab(spec);

    tabHost.setCurrentTab(0);
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11557440

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档