2011-12-09 56 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

不工作..: ( –