我正在尝试在布局中使用BottomSheet
。
根视图是CoordinatorLayout
,我想在底部工作表的顶部设置Elevation
,所以我设置了一个较高的值(50dp),但它在应用程序运行时没有显示但是它出现在android studio设计工具上。
我尝试使用纯色而不是渐变来设置工作表的背景,但它仍然可以正常工作。我也尝试使用阴影形状,但它没有提供相同的高程外观。
这是我的XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.atefhares.StartActivity"
android:clipToPadding="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/DetailsView"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Details Should be shown here"
android:id="@+id/textView"
android:textSize="25sp"
android:padding="20dp" />
</LinearLayout>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.atefhares.Start_Activity" />
</LinearLayout>
<android.support.v4.widget.SlidingPaneLayout
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:behavior_peekHeight="70dp"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
android:background="@drawable/gradiant"
android:fillViewport="true"
android:elevation="50dp">
<include layout="@layout/bottom_sheet_layout"/>
</android.support.v4.widget.SlidingPaneLayout>
</android.support.design.widget.CoordinatorLayout>
编辑: bottom_sheet_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:orientation="vertical">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="@color/colorPrimary"
android:padding="10dp"
android:id="@+id/inviteLL">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:id="@+id/imageView"
android:background="@drawable/invite_icon"
android:layout_margin="5dp"
android:layout_gravity="center_vertical" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Invite Friends"
android:textSize="22sp"
android:textColor="#ffffff"
android:padding="10dp"
android:fontFamily="sans-serif-condensed"
android:gravity="center_vertical"
android:id="@+id/inviteTV"
android:layout_gravity="center_vertical"
android:layout_weight="1" />
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:id="@+id/arrowIV"
android:layout_gravity="center_vertical"
android:background="@drawable/arrow_up" />
</LinearLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="@+id/usersLV"
android:dividerHeight="1dp"
android:divider="#ffffff"
android:background="#ffffff" />
</LinearLayout>
所以如何在Bottom Sheet
任何人都可以帮忙吗?
答案 0 :(得分:2)
答案是:不,这是不可能的(除非您在顶部创建自己的具有高程功能的视图自定义)。
Elevetion 并不意味着在视图的顶部可见,而是在底部,右侧和左侧。
如果您仔细查看official Material Design指南,可以看到底栏根本没有它(不要与卡片和底栏之间的灰色空间混淆)。
例如:从Android Studio导入卡片视图示例,并使用模拟器或您的设备进行播放。你会看到,如果你增加高程值,除了在顶部之外,视图将在任何地方都有阴影(见下面的第二张图片)。
另一个例子是通过导入 Elevation Basic 。
修改强>
以下代码来自卡片视图示例。有一个包含CardView
提升的布局。每当你改变高程时,你总会看到阴影到处都是,但不是在顶部(代码是用Lollipop和Marshmallow测试的)。
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
>
<android.support.v7.widget.CardView
android:id="@+id/cardview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:elevation="100dp"
card_view:cardBackgroundColor="@color/cardview_initial_background"
card_view:cardCornerRadius="8dp"
android:layout_marginLeft="@dimen/margin_large"
android:layout_marginRight="@dimen/margin_large"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/margin_medium"
android:text="@string/cardview_contents"
/>
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_large"
android:orientation="horizontal"
>
<TextView
android:layout_width="@dimen/seekbar_label_length"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/cardview_radius_seekbar_text"
/>
<SeekBar
android:id="@+id/cardview_radius_seekbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/margin_medium"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:layout_width="@dimen/seekbar_label_length"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/cardview_elevation_seekbar_text"
/>
<SeekBar
android:id="@+id/cardview_elevation_seekbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/margin_medium"
/>
</LinearLayout>
</LinearLayout>
答案 1 :(得分:1)
根据google guidelines使用android:提升是不可能的(另外你可以阅读更多关于keyligth)。
无论如何,在最常见的情况下,向上滚动“BottomSheet”时,“BottomSheet”后面会出现一个半透明层,这有助于让用户专注于“BottomSheet”操作,如these examples。
如果你想要一个顶部阴影,你可以用这样的渐变设置一个可绘制的背景(shadow_top.xml):
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="90"
android:centerColor="#000000"
android:endColor="@android:color/transparent"
android:startColor="#000000"
android:type="linear" />
你的SlidingPanelLayout将是:
<android.support.v4.widget.SlidingPaneLayout
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:behavior_peekHeight="95dp"
android:paddingTop="25dp"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
android:background="@drawable/shadow_top"
android:fillViewport="true"
>
最好的问候。
答案 2 :(得分:0)
不要忘记绘制阴影必须使用hardwareAccelerated drawing
有关详细信息,请参阅Android Hardware Acceleration
答案 3 :(得分:0)
试试这个,
<android.support.v4.widget.SlidingPaneLayout
android:id="@+id/bottom_sheet"
xmlns:slide_panel="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:behavior_peekHeight="70dp"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
android:background="@drawable/gradiant"
android:fillViewport="true"
slide_panel:elevation="50dp">