YXTS122
2017-04-19 21:23
采纳率: 100%
浏览 4.3k

android,运行后两个TextView前后重叠了

图片说明

 package com.example.tabdemo;

import android.app.TabActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class TabDemoActivity extends TabActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tab_demo);
        TabHost tabHost=getTabHost();
        LayoutInflater layoutInflater=LayoutInflater.from(this);
        View view=layoutInflater.inflate(R.layout.activity_tab_demo, tabHost.getTabContentView(),true);

        TabSpec spec1=tabHost.newTabSpec("tab1");
        spec1.setIndicator("tab1");
        spec1.setContent(R.id.view1);
        tabHost.addTab(spec1);

        TabSpec spec2=tabHost.newTabSpec("tab2");
        spec2.setIndicator("tab2");
        spec2.setContent(R.id.view2);
        tabHost.addTab(spec2);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.tab_demo, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

图片说明

8条回答 默认 最新

相关推荐 更多相似问题