【问题标题】:How to give bottom shadow to FragmentTabHost in android?如何在android中为Fragment TabHost提供底部阴影?
【发布时间】:2017-04-24 16:52:06
【问题描述】:

您好,我希望我的片段中的标签主机有阴影。我的 XML 代码是

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="60dip"
>
<android.support.v4.app.FragmentTabHost
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
   <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="0" />
</android.support.v4.app.FragmentTabHost>
<FrameLayout
    android:id="@+id/realtabcontent"
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_weight="1" />
</LinearLayout>

我尝试了 stackoverflow 上所有可用的解决方案,但它不起作用。请帮忙。

【问题讨论】:

  • 你试过在 FragmentTabHost 的背景下的 Layer-list shadow 吗?
  • 不。如何做到这一点?
  • 你试过android:elevation=""这个属性吗?

标签: android xml fragment android-tabhost shadow


【解决方案1】:

Android没有这个属性,用来显示阴影。但可能的方法是:

  1. 添加一个灰色的纯线性布局,在其上添加您的实际布局,底部边距为 1 或 2 dp

  2. 有一个带有阴影的 9-patch 图像并将其设置为线性布局的背景

试试这个.. 创建 layout_shadow.xml 并放入 drawable 文件夹

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#CABBBBBB"/>
            <corners android:radius="2dp" />
        </shape>
    </item>

    <item
        android:left="0dp"
        android:right="0dp"
        android:top="0dp"
        android:bottom="2dp">
        <shape android:shape="rectangle">
            <solid android:color="@android:color/white"/>
            <corners android:radius="2dp" />
        </shape>
    </item>
</layer-list>

像这样应用到您的布局

 android:background="@drawable/layout_shadow"

标签宿主的最终布局

<android.support.v4.app.FragmentTabHost
android:id="@android:id/tabhost"
android:background="@drawable/layout_shadow"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

如果不行请告诉我

【讨论】:

  • 不,它不工作。它给整个页面提供框阴影。但我只想要标签的底部阴影。
  • 如果它不适合 2dp,它在这里工作得很好只需将 android:bottom="4dp" 属性更改为 4dp 或 10dp 并检查
  • 试试 LinerLayout 比
【解决方案2】:

Layer-list drawable 是通过在背景中设置为视图赋予阴影效果的方法之一。

请按照此link 为视图创建不同的drawable,并检查此链接中提到的View Box Shadows

【讨论】:

  • 我只想要底部阴影。
  • 链接在哪里?
  • @Mhandroid :是的,你可以设置底部。那里有解释
  • 这个链接对普通布局很有用,但对我的标签没有用:(
  • 请勾选该链接下的视图框阴影
【解决方案3】:

由于我使用的是 fragmenttabhost,因此无法操作它的视图。

【讨论】:

    猜你喜欢
    • 2018-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-26
    • 1970-01-01
    • 2015-01-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多