标题栏没有获得full_parent宽度

时间:2011-08-22 10:51:36

标签: android

我正在设计一个包含标题标题栏的应用程序,我使用以下xml来创建标题栏。但我无法显示全宽,如果我使用fill_parent它的行为真的很奇怪。任何想法或任何建议如何创建标题标题栏,增加降低高度。非常感谢。

window_title.xml lay out below. 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:padding="0px"
    android:layout_width="fill_parent"
    android:layout_height="60px"
    android:background="#323331">

    <ImageView 
        android:id="@+id/header" 
        android:src="@drawable/header"
        android:layout_width="fill_parent" 
        android:layout_height="60px"/>
</LinearLayout>

.java file 

        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

        setContentView(R.layout.main);

        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);

2 个答案:

答案 0 :(得分:0)

如果您不需要默认标题,请使用此选项。 这就是你所需要的一切。

requestWindowFeature(Window.FEATURE_NO_TITLE);

在setContentView之后添加。没有其他需要。

答案 1 :(得分:0)

您的代码是正确的,但您应该为ImageView来源使用9个补丁绘图。试试,例如这一行,你会发现它有效。

android:src="@android:drawable/dark_header"

dark_header这是来自android sdk的9个补丁。您可以在android-sdk/platforms/android-10/data/res/drawable-hdpi文件夹中找到它。

更新。
澄清我在评论中提到的内容。您还应该为标题栏创建自定义样式

<style name="LargeTitleTheme" parent="android:Theme">
    <item name="android:windowTitleSize">60dip</item>
    <item name="android:windowTitleBackgroundStyle">
      @android:drawable/dark_header
    </item>
</style>

并将其添加到AndroidManifest.xml

<activity 
  android:name=".TestActivity"
  android:label="@string/app_name" 
  android:theme="@style/LargeTitleTheme">