私はこれについていくつかのおしゃべりを見てきましたが、明確なものは何もありません. TabWidget のタブを画面の下部に配置する方法はありますか? もしそうなら、どのように?
私は次のことを試しましたが、うまくいきませんでした:
a) tabwidget をフレームレイアウトの下に
設定する b) tabwidget の重力を「bottom」に設定する
ありがとう!イラポール
画面の下部にタブを表示するための最も簡単で、最も堅牢で、スケーラブルなソリューションを次に示します。
layout_height
FrameLayoutとwrap_content
TabWidget の両方に 設定android:layout_weight="1"
android:layout_weight="0"
します (0 がデフォルトですが、強調、読みやすさなどのため)android:layout_marginBottom="-4dp"
(下の仕切りを削除するため)完全なコード:
<?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"
android:padding="5dp">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_weight="1"/>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_marginBottom="-4dp"/>
</LinearLayout>
</TabHost>
試してみてください;)スクロールの場合にどのように処理されるかわからないので、FrameLayout(@ id / tabcontent)のコンテンツを見てください...私の場合、タブのコンテンツとしてListViewを使用したので機能します。:) それが役に立てば幸い。
<?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">
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_above="@android:id/tabs" />
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>
</TabHost>
線を消す方法があります。
1) このチュートリアルに従ってください: android-tabs-with-fragments
2) 次に、Leaudro が上で提案した RelativeLayout の変更を適用します (すべての FrameLayout にレイアウト プロパティを適用します)。
また、項目 1 の tab.xml に ImageView を追加して、非常に iPhone のような外観のタブを取得することもできます。
ここに私が今取り組んでいることのスクリーンショットがあります。主にアイコンのセレクターを作成し、水平方向の均等な分布を確保するために、まだやるべきことがいくつかありますが、アイデアはわかります。私の場合、フラグメントを使用していますが、標準のタブ ビューにも同じ原則が適用されます。
tabWidget の区切り線を削除しようとするすべての人のために、ここにサンプル プロジェクト (およびそれぞれのチュートリアル) があります。これは、タブをカスタマイズして、タブが下部にある場合の問題を解決するのに最適です。Eclipse プロジェクト: android-custom-tabs ; 元の説明:ブログ; これが役に立ったことを願っています。
Androidのすべてのバージョン(特にカスタムUIのもの)で機能するかどうかはわかりませんが、追加することで下部の灰色のバーを削除できました
android:layout_marginBottom="-3dp"
TabWidget XML に...
はい、参照してください:link、しかし彼は新しいタブを作成するためにアクティビティではなくxmlレイアウトを使用したので、彼のxmlコード(FrameLayout-0pxのpaddingTopを設定)を入れてからコードを書きます:
public class SomeActivity extends ActivityGroup {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tab_host = (TabHost) findViewById(R.id.edit_item_tab_host);
tab_host.setup(this.getLocalActivityManager());
TabSpec ts1 = tab_host.newTabSpec("TAB_DATE");
ts1.setIndicator("tab1");
ts1.setContent(new Intent(this, Registration.class));
tab_host.addTab(ts1);
TabSpec ts2 = tab_host.newTabSpec("TAB_GEO");
ts2.setIndicator("tab2");
ts2.setContent(new Intent(this, Login.class));
tab_host.addTab(ts2);
TabSpec ts3 = tab_host.newTabSpec("TAB_TEXT");
ts3.setIndicator("tab3");
ts3.setContent(new Intent(this, Registration.class));
tab_host.addTab(ts3);
tab_host.setCurrentTab(0);
}
}
これはまさにあなたが探しているものではないかもしれません (タブを画面の下部に送るのは「簡単な」解決策ではありません) が、それでも私があなたにフラグを立てたい興味深い代替解決策です:
ScrollableTabHostは、TabHost のように動作するように設計されていますが、より多くの項目に対応するための追加のスクロールビューを備えています ...
このオープンソース プロジェクトを掘り下げると、質問に対する答えが見つかるかもしれません。もっと簡単なものがあれば、あなたに戻ってきます。
Androidタブを画面の下部に配置しようとすると、同じ問題が発生しました。私のシナリオは、レイアウト ファイルを使用せず、コードでタブを作成することでした。また、他のアプローチを使用すると少し複雑すぎると思われる各タブからアクティビティを起動することも検討していたので、問題を克服するためのサンプル コードを次に示します。
このコードを安定した作業に使用することをお勧めします。タブ内のネストされたフラグメント (ネストされた MapFragment など) 用に最適化され、「アクティビティを保持しない」でテストされました: https://stackoverflow.com/a/23150258/2765497