2015-03-03 25 views
0

我已經建立了一個新的Android工具欄:Android父視圖:如何減少工具欄的大小?

android:layout_height="?attr/actionBarSize" 

工具欄在屏幕頂部顯示正確。我遇到的問題是應用程序屏幕其餘部分的背景圖像頂部被工具欄覆蓋。我需要通過佈局文件中工具欄的高度來減小容納背景圖像的容器的高度,但是沒有任何運氣。

工具欄顯示正確。它有一個圖像作爲背景。

下面是main.xml中的文件:

<RelativeLayout 

xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="@drawable/big_wave" 
tools:context=".MainActivity" > 

<android.support.v7.widget.Toolbar 

    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/toolbar" 
    android:layout_height="?attr/actionBarSize" 
    android:layout_width="match_parent" 
    android:background="@drawable/actionbar_skypic" /> 


</RelativeLayout> 
+0

飼養背景,在工具欄上透明也將正確解決問題了嗎? – 2015-03-03 07:20:00

回答

1

可以調整自己的形象,不能你的身高是多少?或者,您可以將工具背景設置爲半透明或透明。

toolbar.getBackground().setAlpha(0); 
+0

工具欄背景設置爲可繪製圖像並正確顯示。就好像父視圖沒有看到或識別工具欄的高度。 如果總的垂直屏幕高度是100並且工具欄垂直高度是10,我試圖找到屏幕背景可繪製的方式來顯示剩餘的90高度。 – AJW 2015-03-03 08:26:52

+0

你可以發表你的言論嗎? 因爲你總是可以使用各種尺寸的佈局,並以任何你想要的顏色來繪製它們。 – 2015-03-03 08:33:34

+0

我會在原來的問題上面發佈。 – AJW 2015-03-03 08:36:02

0

可以使用android:layout_below財產

<LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="?attr/colorPrimaryDark" /> 

     <com.example.sample.SlidingTabLayout 
       android:id="@+id/sliding_tabs" 
       android:background="?attr/colorPrimaryDark" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" /> 

      <android.support.v4.view.ViewPager 
       android:id="@+id/viewpager" 
       android:layout_width="match_parent" 
       android:layout_height="0px" 
       android:layout_weight="1" 
       android:background="@android:color/white" /> 
     </LinearLayout> 

這裏是輸出。 enter image description here

你可以看到工具欄下面有滑動佈局選項卡

+0

試過這個和相同的結果...工具欄覆蓋主背景圖像的頂部。 – AJW 2015-03-03 08:27:36

+0

我已經更新了我的答案。檢查這是否有助於你。 – 2015-03-03 08:55:17