1

ActionBarIcon、Tabs、MenuButtonを1行で作成したいのですが、次のコードを使用すると、PrintScreenのように2行になります。

java:

viewPager = (ViewPager) findViewById(R.id.pager);
bar = getSupportActionBar();
bar.setIcon(R.drawable.ic_map);
bar.setDisplayShowHomeEnabled(false);
bar.setDisplayShowTitleEnabled(false);
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

TabsAdapter tabsAdapter = new TabsAdapter(this, viewPager);
tabsAdapter.addTab(bar.newTab().setText("A"), ClientTemplates.class, null);
tabsAdapter.addTab(bar.newTab().setText("B"), ClientWalletsCards.class, null);
tabsAdapter.addTab(bar.newTab().setText("C"), ClientReports.class, null);

XML:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

<android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:paddingRight="1px"
        android:paddingLeft="1px"/>

1行だけを取得するには、コードで何を変更する必要がありますか?

4

2 に答える 2

2

AFAIK、あなたはこれを制御することはできません。Android(またはこの場合はActionBarSherlock)は、アクションバーのタブを必要な場所に配置したり、必要に応じてタブからドロップダウンリストに変換したりします。

ただし、を使用するandroid:uiOptions="splitActionBarWhenNarrow"と、オーバーフローメニューボタンの行を画面の下部に配置できます。

于 2012-09-21T16:21:05.720 に答える
0

アクションバーCustomViewは、必要な効果を実現するための優れた方法です。次のように、自分でタブを作成します。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="right">

    <RelativeLayout 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <RelativeLayout 
            android:id="@+id/tabone"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginLeft="@dimen/actionbar_margin">
            <ImageView
                android:contentDescription="@string/tabone_discription"
                android:id="@+id/mainpage"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/account_dark"
                android:layout_centerInParent="true"
                />
        </RelativeLayout>

        <ImageView 
            android:contentDescription="@string/divider_discription"
            android:id="@+id/divider1"
            android:background="@drawable/list_divider_holo_light"
            android:layout_height="match_parent"
            android:layout_marginTop="@dimen/divider_margin_top_bottom"
            android:layout_marginBottom="@dimen/divider_margin_top_bottom"
            android:layout_toRightOf="@id/tabone"
            android:layout_marginLeft="@dimen/actionbar_margin"
            android:layout_width="@dimen/divider_width"/>

        <RelativeLayout 
            android:id="@+id/tabtwo"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_toRightOf="@id/divider1"
            android:layout_marginLeft="@dimen/actionbar_margin">
            <ImageView 
                android:contentDescription="@string/tabtwo_discription"
                android:id="@+id/atpage"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/at_dark"
                android:layout_centerInParent="true"
                />
        </RelativeLayout>

        <ImageView 
            android:contentDescription="@string/divider_discription"
            android:id="@+id/divider2"
            android:background="@drawable/list_divider_holo_light"
            android:layout_height="match_parent"
            android:layout_marginTop="@dimen/divider_margin_top_bottom"
            android:layout_marginBottom="@dimen/divider_margin_top_bottom"
            android:layout_marginLeft="@dimen/actionbar_margin"
            android:layout_toRightOf="@id/tabtwo"
            android:layout_width="@dimen/divider_width"/>

        <RelativeLayout 
            android:id="@+id/tabthree"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_toRightOf="@id/divider2"
            android:layout_marginLeft="@dimen/actionbar_margin">
            <ImageView 
                android:contentDescription="@string/tabthree_discription"
                android:id="@+id/replaypage"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/comment_dark"
                android:layout_centerInParent="true"
                />
        </RelativeLayout>

        <View 
            android:layout_height="0dp"
            android:layout_width="0dp"
            android:layout_toRightOf="@id/tabthree"
            android:layout_marginLeft="12dp"/>

    </RelativeLayout>

    <ImageView 
        android:contentDescription="@string/actionbar_line"
        android:layout_height="3dp"
        android:layout_width="0dp"
        android:id="@+id/actionbarline"
        android:background="@drawable/ab_solid_custom_blue_inverse_holo"
        />

</RelativeLayout>

次に、アクティビティJavaファイルで:

mActionBar.setDisplayShowCustomEnabled(true);
mActionBar.setCustomView(R.layout.ab_customview);

タブを使用しませんでしたが、結果は、アクションバーの同じ行に3つのタブがあるように見えます:)

于 2013-11-22T07:20:15.580 に答える