0

私はAndroid開発の初心者で、カスタムタブを作成しようとしています。ただし、アプリケーションを実行すると、タブが画面の高さ全体に表示され、何らかの理由でOnCreate中にソフトキーボードが表示されます。これは、tabhostがコンテンツの設定に失敗しているのか、レイアウトインフレーターのパラメーターが正しくないのか、それとも私が見逃している何かが原因なのかを判断できません。このチュートリアルをガイドとして使用したので、なぜこの問題が発生するのかわかりません。どんな助けでも大歓迎です。

私のコード;

inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);        
    th = (TabHost)findViewById(R.id.tabhost);

    calTab = inflater.inflate(R.layout.tab, th.getTabWidget(), false);
    calTab.setLayoutParams(params);
    label = (TextView) calTab.findViewById(R.id.tabLabel);
    label.setText("CALC");
    divider = (TextView) calTab.findViewById(R.id.tabSelectedDivider);
    divider.setVisibility(View.VISIBLE);        

    newsTab = inflater.inflate(R.layout.tab, th.getTabWidget(), false);
    newsTab.setLayoutParams(params);
    label = (TextView) newsTab.findViewById(R.id.tabLabel);
    label.setText("NEWS");

    fdTab = inflater.inflate(R.layout.tab, th.getTabWidget(), false);
    fdTab.setLayoutParams(params);
    label = (TextView) fdTab.findViewById(R.id.tabLabel);
    label.setText("FIND");

    pTab = inflater.inflate(R.layout.tab, th.getTabWidget(), false);
    pTab.setLayoutParams(params);
    label = (TextView) pTab.findViewById(R.id.tabLabel);
    label.setText("PORT");


    th.setup();

    specs1 = th.newTabSpec("tag1");
    specs1.setContent(R.id.tab1);
    specs2 = th.newTabSpec("tag2");
    specs2.setContent(R.id.tab2);
    specs3 = th.newTabSpec("tag3");     
    specs3.setContent(R.id.tab3);
    specs4 = th.newTabSpec("tag4");     
    specs4.setContent(R.id.tab4);
    if(android.os.Build.VERSION.SDK_INT>10){ 
        specs1.setIndicator(calTab);
        specs2.setIndicator(newsTab);
        specs3.setIndicator(fdTab);
        specs4.setIndicator(pTab);
    }else{
        specs1.setIndicator("CAL",getResources().getDrawable(R.drawable.calculatortab));
        specs2.setIndicator("NEWS",getResources().getDrawable(R.drawable.news));
        specs3.setIndicator("FIND ", getResources().getDrawable(R.drawable.maptab));
        specs4.setIndicator("PORT", getResources().getDrawable(R.drawable.portfoliotab));
    }
    th.addTab(specs1);
    th.addTab(specs2);
    th.addTab(specs3);
    th.addTab(specs4); 
    th.setOnTabChangedListener(Activity.this);

TAB XML

<?xml version="1.0" encoding="utf-8"?>

<TextView
    android:id="@+id/tabLabel"
    android:layout_width="fill_parent"
    android:layout_height="43dp"
    android:gravity="center_vertical|center_horizontal"
    android:textColor="#FFF"
    android:textSize="12dp"/>

<TextView
    android:id="@+id/tabSelectedDivider"
    android:layout_width="fill_parent"
    android:layout_height="5dp"
    android:layout_alignParentBottom="true"
    android:background="#3366CC"
    android:visibility="gone" />

<TextView
    android:id="@+id/tabDivider"
    android:layout_width="fill_parent"
    android:layout_height="2dp"
    android:layout_alignParentBottom="true"
    android:background="#3366CC" />

<TextView
    android:id="@+id/tabSplitter"
    android:layout_width="1px"
    android:layout_height="23dp"
    android:layout_alignParentRight="true"
    android:layout_marginTop="10dp"
    android:background="#333" />

TABHOSTを使用したメインXML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TabHost
    android:id="@+id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent" > <!-- changed from match parent -->

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </TabWidget>

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <FrameLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:sat="http://schemas.android.com/apk/res/com.bryanjrichardson.GSCC"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >



            <LinearLayout
                android:id="@+id/tab1"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >

...and so forth
4

1 に答える 1

1

タブウィジェットに一定の高さを与える必要があります。したがって、ウィジェットの高さのコンテンツをラップする代わりに、60dpなどの見た目に美しい値を入力する必要があります。

于 2013-02-09T03:30:19.333 に答える