2011-12-09 55 views
0

我已經創建了一個自定義選項卡布局,看起來像這樣,我想使底部欄的頂部欄的背景相同,這意味着在兩部分中的陰影我怎麼可以這樣做,請建議:自定義選項卡欄與在android中的陰影背景

這是我的main.xml

<?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="fill_parent" android:background="@drawable/bac_tab" 
android:id="@+id/mymain_layout" android:weightSum="1"> 

<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:background="@drawable/bac_tab"> 
    <LinearLayout android:orientation="vertical" 
     android:layout_width="fill_parent" android:layout_height="fill_parent"> 
     <View android:layout_width="fill_parent" android:layout_height="0.5dip" 
      android:background="#000" /> 
     <TabWidget android:id="@android:id/tabs" android:layout_marginTop="5dip" android:layout_marginBottom ="5dip" 
      android:layout_width="fill_parent" 
      android:layout_marginLeft="30dip" android:layout_marginRight="30dip" android:background="@null" 
      android:layout_height="40dp" /> 

     <FrameLayout android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" android:layout_height="fill_parent"> 
      <LinearLayout android:background="#ffffff" 
       android:orientation="vertical" android:layout_width="fill_parent" 
       android:layout_height="fill_parent" android:id="@+id/main"> 
       <ListView android:id="@+id/list" android:layout_width="fill_parent" 
        android:background="#ffffff" android:layout_height="fill_parent" 
        android:layout_weight="1" /> 
       <TextView android:id="@+id/empty" android:layout_width="wrap_content" 
        android:layout_height="wrap_content" android:gravity="center" 
        android:text="" android:textColor="#000000" /> 
      </LinearLayout> 
      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/mainlayout" android:orientation="vertical" 
       android:layout_width="fill_parent" android:layout_height="fill_parent"> 
       <TextView android:id="@+id/empty" android:layout_width="wrap_content" 
        android:layout_height="wrap_content" android:gravity="center" 
        android:text="" android:textColor="#000000" /> 

      </RelativeLayout> 
     </FrameLayout> 
    </LinearLayout> 
</TabHost> 
<RelativeLayout android:gravity="bottom" 
    android:layout_width="fill_parent" android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" android:background="@drawable/bac_tab"> 

</RelativeLayout> 

和bac_tab.xml

<?xml version="1.0" encoding="utf-8"?> 
<selector 
xmlns:android="http://schemas.android.com/apk/res/android"> 


<item>   
    <shape> 
     <gradient 
      android:endColor="#000000" 
      android:startColor="#696969" 
      android:centerColor="#696969" 
      android:angle="270" /> 
     <stroke 

      android:color="#696969" /> 
     <padding 
      android:left="2dp" 
      android:top="3dp" 
      android:right="2dp" 
      android:bottom="3dp" /> 
    </shape> 
</item> 

回答

1

我通過使用用於TabHost透明背景,並使用陰影的背景作爲第一層得到了理想的結果:

<?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="fill_parent" android:background="@drawable/bac_tab" 
android:id="@+id/mymain_layout" android:weightSum="1"> 

*<!---by adding this in the background-----> 

    <RelativeLayout android:gravity="bottom" 
      android:layout_width="fill_parent" android:layout_height="51dp" 
      android:layout_alignParentTop="true" android:layout_alignParentLeft="true" 
      android:background="@drawable/newbac"></RelativeLayout> 

    <!---------------------------------------------------------->* 

    <TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@android:id/tabhost" android:layout_width="fill_parent" 
     android:layout_height="fill_parent" ***android:background="@drawable/@android:color/transparent">*** 
     <LinearLayout android:orientation="vertical" 
      android:layout_width="fill_parent" android:layout_height="fill_parent"> 
      <View android:layout_width="fill_parent" android:layout_height="0.5dip" 
       android:background="#000" /> 
      <TabWidget android:id="@android:id/tabs" android:layout_marginTop="5dip" android:layout_marginBottom ="5dip" 
       android:layout_width="fill_parent" 
       android:layout_marginLeft="30dip" android:layout_marginRight="30dip" android:background="@null" 
       android:layout_height="40dp" /> 

      <FrameLayout android:id="@android:id/tabcontent" 
       android:layout_width="fill_parent" android:layout_height="fill_parent"> 
       <LinearLayout android:background="#ffffff" 
        android:orientation="vertical" android:layout_width="fill_parent" 
        android:layout_height="fill_parent" android:id="@+id/main"> 
        <ListView android:id="@+id/list" android:layout_width="fill_parent" 
         android:background="#ffffff" android:layout_height="fill_parent" 
         android:layout_weight="1" /> 
        <TextView android:id="@+id/empty" android:layout_width="wrap_content" 
         android:layout_height="wrap_content" android:gravity="center" 
         android:text="" android:textColor="#000000" /> 
       </LinearLayout> 
       <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
        android:id="@+id/mainlayout" android:orientation="vertical" 
        android:layout_width="fill_parent" android:layout_height="fill_parent"> 
        <TextView android:id="@+id/empty" android:layout_width="wrap_content" 
         android:layout_height="wrap_content" android:gravity="center" 
         android:text="" android:textColor="#000000" /> 

       </RelativeLayout> 
      </FrameLayout> 
     </LinearLayout> 
    </TabHost> 
    <RelativeLayout android:gravity="bottom" 
     android:layout_width="fill_parent" android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" android:background="@drawable/bac_tab"> 

    </RelativeLayout> 
0

嘗試使用層列表

<?xml version="1.0" encoding="utf-8"?> 
<layer-list 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    > 
    <item> 
     <shape 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:shape="rectangle" 
      > 

      <gradient 
       android:endColor="#000000" 
      android:startColor="#696969" 
      android:angle="270" 
      android:centerColor="#696969" 


       android:type="linear" 
       />  
     </shape> 
    </item> 

</layer-list> 
+0

不工作..: ( –