简体   繁体   English

Android设置自定义标题栏的高度

[英]Android set height of custom title bar

I made a custom title bar. 我做了一个自定义标题栏。 In the title bar are two imageviews next to each other and one textview beneath it. 标题栏中是两个彼此相邻的图像视图,下面是一个文本视图。 It works fine but I just see the top of the textview. 它工作正常,但我只看到textview的顶部。 So I think the title bar get cropped at the underside. 所以我认为标题栏在底部被裁剪。 Does somebody know how to set the height of a custom title bar? 有人知道如何设置自定义标题栏的高度吗? EDIT: My custom title bar: 编辑:我的自定义标题栏:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="45dip"
    android:orientation="vertical"
    android:id="@+id/header_root"> 
<RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
<ImageView
    android:id="@+id/header_image"
    android:layout_width="wrap_content"
    android:layout_height="27dip"
    android:src="@drawable/header_image"
    />

<ImageView
    android:id="@+id/options"
    android:layout_width="wrap_content"
    android:layout_height="27dip"
    android:layout_margin="-8dip"
    android:layout_toRightOf="@+id/header_image"
    android:src="@drawable/options" />

</RelativeLayout>
<TextView 
    android:text="Vissenencyclopedie"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:textSize="15dp"
    android:id="@+id/titel"
    android:layout_marginTop="-7dip"
    />
</LinearLayout>  

Use style: 使用方式:

 <style name="CustomTheme" parent="@android:style/Theme.Light">
    <item name="android:windowTitleSize">30dp</item>
</style>

And add to manifest: 并添加到清单:

 <activity
        android:name=".MainActivity"
        android:theme="@style/CastomTheme" >
 </activity>

I am assuming that the title bar is within some sort of layout, so what you can do is to set the height of the layout, for example: 我假设标题栏在某种布局中,所以你可以做的是设置布局的高度,例如:

android:height="30dp"

You can also provide padding for the textviews, for example: 您还可以为textviews提供填充,例如:

android:paddingBottom="10dp"

This should make sure that the text is displayed. 这应该确保显示文本。 Hope this helps. 希望这可以帮助。

I assume the problem lies in the android:layout_height="45dip" you specified for your outer LinearLayout. 我假设问题在于你为外部LinearLayout指定的android:layout_height="45dip" Replace that line with android:layout_height="wrap_content" and I suppose this will solve your problem. android:layout_height="wrap_content"替换该行,我想这将解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM