我创建了一个自定义标签布局,看起来像这样,我想让顶栏的背景与底栏相同,意思是两部分阴影我怎么能这样做,请建议:
这是我的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>
答案 0 :(得分: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>
答案 1 :(得分: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>