2013-08-22 26 views
1

林给我的应用程序自定义标题栏,它似乎是半隐藏在主网页内容的背后: enter image description here安卓:自定义标题栏不适合页面

styles.xml我有:

</style> 
    <style name="NewsAppTheme" parent="android:Theme.Light" > 
</style> 

main.xml中(带标题栏的页面)

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:padding="@dimen/tiny_4dp" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 
     <!-- Top Row --> 
     <LinearLayout 
      android:baselineAligned="false" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <RelativeLayout 
       android:id="@+id/relative_1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:padding="@dimen/tiny_4dp" > 

       <ImageView 
        android:id="@+id/img_head" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:clickable="true" 
        android:contentDescription="@string/text_head" 
        android:scaleType="fitXY" 
        android:src="@drawable/headlines" /> 

       <TextView 
        android:id="@+id/text_head" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_alignLeft="@id/img_head" 
        android:layout_alignRight="@id/img_head" 
        android:layout_alignTop="@id/img_head" 
        android:gravity="left" 
        android:padding="@dimen/medium_15dp" 
        android:text="@string/text_head" 
        android:textSize="@dimen/large_20dp" 
        android:textStyle="bold" /> 

      </RelativeLayout> 

      <RelativeLayout 
       android:id="@+id/relative_2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:padding="@dimen/tiny_4dp" > 

       <ImageView 
        android:id="@+id/img_custom1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:clickable="true" 
        android:contentDescription="@string/text_custom1" 
        android:scaleType="fitXY" 
        android:src="@drawable/headlines" /> 

       <TextView 
        android:id="@+id/text_custom1" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_alignLeft="@id/img_custom1" 
        android:layout_alignRight="@id/img_custom1" 
        android:layout_alignTop="@id/img_custom1" 
        android:gravity="left" 
        android:padding="@dimen/medium_15dp" 
        android:text="@string/text_custom1" 
        android:textSize="@dimen/large_20dp" 
        android:textStyle="bold" /> 

      </RelativeLayout> 
     </LinearLayout> 


     ..... and so on 


    </LinearLayout> 
</ScrollView> 

titlebar.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="35dp" 
    android:layout_gravity="center_horizontal" 
    android:orientation="horizontal" 
    android:padding="@dimen/small_8dp" > 

    <ImageView 
     android:id="@+id/title_menu" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:paddingLeft="@dimen/small_8dp" 
     android:src="@drawable/ic_grid" 
     android:contentDescription="@string/title_menu"/> 

    <TextView 
     android:id="@+id/title_title" 
     android:layout_width="0dip" 
     android:layout_height="match_parent" 
     android:layout_gravity="center_vertical" 
     android:layout_weight="1" 
     android:paddingLeft="@dimen/small_8dp" 
     android:paddingRight="@dimen/small_8dp" 
     android:paddingTop="@dimen/tiny_4dp" 
     android:text="@string/title_title" /> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="right|center_vertical" 
     android:orientation="horizontal" > 

     <ImageView 
      android:id="@+id/title_minus" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:contentDescription="@string/title_minus" 
      android:paddingRight="@dimen/small_8dp" 
      android:src="@drawable/ic_minus" /> 

     <ImageView 
      android:id="@+id/title_add" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:contentDescription="@string/title_add" 
      android:paddingRight="@dimen/small_8dp" 
      android:src="@drawable/ic_ok" /> 
    </LinearLayout> 

</LinearLayout> 

有件事情我已经做了导致其切断的标题栏?我一直在教练说,酒吧应该是35dp高,虽然改变似乎没有太大的影响。

+2

如果您为titleBar使用'android:layout_height =“wap_content”'会怎么样? – codeMagic

+1

使用'android:layout_height =“wrap_content”'而不是'android:layout_height =“35dp”' – VenomVendor

+0

谢谢,如果你发布这个答案我会接受它:D – Edd

回答

2

你需要改变你的titlebar.xmlheight,以确保它得到需要这样其他Views,这layout包括在不占用它需要的房间数量。因此,将height更改为wrap_content而不是固定的dp

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" <!-- this guy here --> 
android:layout_gravity="center_horizontal" 
android:orientation="horizontal" 
android:padding="@dimen/small_8dp" >