簡體   English   中英

自定義操作欄布局未獲得正確的寬度

[英]Custom Action bar layout not getting proper width

我正在嘗試為帶有導航抽屜的操作欄使用自定義布局,但是寬度似乎不一致。

現在是這樣的:

ListView http://imageshack.com/a/img673/867/fTvd6X.png

由於某種原因,寬度沒有完全占據在操作欄的左側。

自定義操作欄中當前使用的項目是:應用程序名稱(文本視圖),微調框(某些文本),微調框右側的ImageView。

這是我的布局xm的樣子:

   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <ImageView
        android:layout_width="35dp"
        android:layout_height="35dp"
        android:padding="10dp"
        android:layout_gravity="center_vertical|left"
        android:src="@drawable/someIcon" />

    <TextView
        android:id="@+id/appTextLabel"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center"
        android:padding="10dp"
        android:text="someAppName"
        android:textColor="#555555"
        android:textSize="24sp"
        android:textStyle="bold" />

    <Spinner
        android:id="@+id/locationSpinner"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="#000"
        android:spinnerMode="dropdown" />

    <ImageView
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_gravity="center_vertical|right"
        android:src="@drawable/location_down_icon" />
</LinearLayout>

以及動作欄的示例代碼:

    mActionBar = getSupportActionBar();

    mActionBar.setDisplayShowTitleEnabled(false);

    mActionBar.setDisplayShowCustomEnabled(true);

    mActionBar.setCustomView(actionBarLayout);

不知道這怎么了。

任何幫助將不勝感激。 謝謝 .. :)

這是圖標(或徽標)的空間嗎?

你可以嘗試

 getActionBar().setDisplayShowHomeEnabled(false);

但是您有標志ActionBar.DISPLAY_SHOW_HOMEActionBar.DISPLAY_HOME_AS_UP ,也許它們對您很重要...

你也可以嘗試設置透明圖標

getActionBar().setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent)));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM