1

当我通过添加图像自定义视图中的标题栏时,我遇到了一个问题,因为图像没有准确地固定在边缘。我附上了图像,您可以在其中看到窗口边距和添加的图像之间的空间。如何克服这个问题。下面是我用来自定义标题栏的代码。谁能帮我解决这个问题。

爪哇代码:

 requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
 setContentView(R.layout.home_view);
 this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
            R.layout.upwindow);

布局代码:

  <?xml version="1.0" encoding="utf-8"?>
  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    
  android:orientation="vertical" 
   android:layout_width="fill_parent"
     android:layout_height="32dp">

     <ImageView
         android:id="@+id/imageView1"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:background="@drawable/up_bar"
         android:src="@drawable/up_bar" />

<TextView 
    android:id="@+id/pagename"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:text="Sify MyStorage"
    android:textAppearance="?android:attr/textAppearanceMedium" />

</RelativeLayout>

在此处输入图像描述

4

4 回答 4

1

你有不同分辨率的不同图像吗?可能是您的图像根本不适合该空间,并且您需要更大的图像。不过要小心,您的应用程序在不同平台上工作时可能会遇到问题。

于 2012-05-11T13:03:57.757 回答
1

在值文件夹中创建样式 xml:

<resources>
  <style name="CustomWindowTitleBackground" /> 
  <style name="CustomTheme" parent="android:Theme">
  <item name="android:windowTitleSize">32dp</item> 
 <item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground
 </item> 

</style>
</resources>

然后在清单中将其称为:

 android:theme="@style/CustomTheme">

这将解决它。

希望这有帮助。

于 2012-05-11T13:05:04.080 回答
1

您需要对样式进行一些操作才能覆盖此行为。定义一个自定义主题(样式),如下所示:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="customTitle">
        <item name="android:background">@drawable/up_bar</item>
    </style>
    <style name="myTheme" parent="android:Theme"> 
        <item name="android:windowTitleBackgroundStyle">@style/customTitle</item>
    </style>
</resources>

然后通过在AndroidManifest.xmlandroid:theme="@style/myTheme"中应用您所需的活动标签,在您的活动中使用此主题

于 2012-05-11T13:05:53.767 回答
1
requestWindowFeature(Window.FEATURE_NO_TITLE);

并将 setBackground 设置为布局文件中的布局...

像,,,

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    
  android:orientation="vertical"  
   android:layout_width="fill_parent"  android:background="@drawable/up_bar" <---Add this
     android:layout_height="32dp">

Remove imageview from xml

于 2012-05-11T13:05:59.363 回答