5

答えを探すのに丸2日を費やした後、次の行動について助けを求めたいと思います.

アクティビティごとのレイアウトを使用して、Android で単純なタブホスト アプリケーションをコーディングしようとしています。タブウィジェットが画面の下部に表示されるようにレイアウトを設計しました。

最初のタブで、単純な 2 行の ListView を挿入しようとしています。私の問題は、ListView が一番下にありますが、その半分がタブウィジェットの後ろに隠れていることです。ListView をタブウィジェットのすぐ上に表示する方法を理解したいと思います。

ここに私の 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">
    <RelativeLayout
        android:layout_height="fill_parent"
        android:layout_width="fill_parent">

       <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp" />

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

</TabHost>

これが私のメインアプリクラスです:

public class TestTabWidget extends TabActivity {

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

        Resources res = getResources(); // Resource object to get Drawables
        TabHost tabHost = getTabHost();  // The activity TabHost
        TabHost.TabSpec spec;  // Resusable TabSpec for each tab
        Intent intent;  // Reusable Intent for each tab

        intent = new Intent().setClass(this, AActivity.class);

        spec = tabHost.newTabSpec("artists").setIndicator("Tab A",
                          res.getDrawable(R.drawable.ic_tab_a))
                      .setContent(intent);
        tabHost.addTab(spec);


        tabHost.setCurrentTab(0);
    }

}

これが私のアクティビティコードです:

public class AActivity extends Activity {

ListView lvListe;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.a_layout);
        lvListe = (ListView)findViewById(R.id.lvListe);
        lvListe.setBackgroundResource(R.layout.tables);

        String[] listeStrings = {"Value 1","Value 2"};

        lvListe.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,listeStrings));

    }
}

アクティビティのレイアウトは次のとおりです。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ListView 
          android:id="@+id/lvListe"
          android:layout_height="wrap_content"
          android:layout_width="wrap_content"
          android:layout_alignParentBottom="true" />
</RelativeLayout>

私を助けてくれる人に感謝します....

アダム

4

1 に答える 1

11

セクションの代わりにこのレイアウトを試してくださいRelativeLayout:

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

  <FrameLayout
    android:id="@android:id/tabcontent"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_above="@android:id/tabs"
    android:padding="5dp" />

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

現在、あなたFrameLayoutは 内のスペース全体を埋めています。これはRelativeLayoutRelativeLayoutアイテムを隣り合わせに配置することを区別せずLinearLayout、オーバーラップを許可するためです。私の調整は、レイアウトの上部にあるウィジェット間のスペースを埋めるようにレイアウトに指示します。

に関するもう 1 つの注意点RelativeLayoutとして、項目の Z オーダーは XML の順序によって決定されます。そのため、 が のTabWidget上に表示されFrameLayoutます。順序を逆にしていたら、 はTabWidget見えなかったでしょう!

それが役立つことを願っています!

于 2011-02-21T18:36:32.183 に答える