0

私はアンドロイドが初めてなので、私の簡単な質問を許してください。:)

テキストビューのテキスト プロパティがこのタブ内に表示されないのはなぜですか?

画面:こちら

これが私のコードです..

MapTab2.java

package com.test.maptab2;

import android.app.TabActivity;
import android.os.Bundle;
import android.widget.TabHost;

public class MapTab2 extends TabActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TabHost.TabSpec spec;

        spec = getTabHost().newTabSpec("tab1");
        spec.setContent(R.id.mapstub);
        spec.setIndicator("Map");
        getTabHost().addTab(spec);

        spec = getTabHost().newTabSpec("tab2");
        spec.setContent(R.id.detailstub);
        spec.setIndicator("Detail");
        getTabHost().addTab(spec);

        getTabHost().setCurrentTab(0);

    }

}

Main.xml

<?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">

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

        <!-- Tab-switch panel -->
        <TabWidget android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"/>

        <!-- Tab contents -->
        <FrameLayout android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">

            <!-- Map here -->
            <TextView android:id="@+id/mapstub"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="map"/>

            <!-- Other stuff -->
            <TextView android:id="@+id/detailstub"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="detail"/>

        </FrameLayout>  
    </LinearLayout>
</TabHost>

タブ内にマップを表示する方法を構築しようとしています。まずは基本を理解するのが一番だと思いました。:')

4

2 に答える 2

1

実際には、親ビュー (この場合は LinearLayout) で重力を設定してから、子ビュー (あなたの場合は TextViews など) で layout_gravity 属性を設定することができました。

この単純な例を機能させるには、すべての「fill_parent」属性を「wrap_content」(または別の方法として 0.0dp) に変更します。その後、さまざまな属性を試して、すべてを希望どおりに正確に配置できます。

于 2012-02-05T14:09:50.247 に答える
0

タブ内のすべてのTextViewにandroid:gravity="center"を追加してみてください。

于 2012-02-05T12:57:29.847 に答える