Android - 线性布局中的海拔

标签 android android-linearlayout

我想使用高程向线性布局添加阴影效果。这是我的 xml 代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/searchFragment">

    <RelativeLayout
        android:id="@+id/RelativeLayout02"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#ffffff">
            <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="horizontal"
                android:clipToPadding="false"
                android:paddingBottom="5dp">

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/linearLayout"
                    android:paddingBottom="5dp"
                    android:elevation="8dp"> ---> here should be elevation

                    <LinearLayout
                        android:orientation="vertical"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:paddingBottom="5dp"
                        android:layout_marginRight="55dp">

                        <AutoCompleteTextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:id="@+id/fromStationField"
                            android:completionThreshold="1"
                            android:hint="From"
                            android:textAlignment="textStart"
                            android:gravity="left|start"
                            android:layout_gravity="left" />

                        <AutoCompleteTextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:id="@+id/toStationField"
                            android:completionThreshold="1"
                            android:hint="To"
                            android:background="@android:color/transparent"
                            android:paddingRight="4dp"
                            android:paddingLeft="4dp" />
                    </LinearLayout>

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:id="@+id/swapButton"
                        android:src="@drawable/ic_swap"
                        android:layout_gravity="center_vertical"
                        android:layout_marginLeft="-55dp"/>
                </LinearLayout>

                <android.support.design.widget.CoordinatorLayout
                    android:id="@+id/main_content"
                    xmlns:android="http://schemas.android.com/apk/res/android"
                    xmlns:app="http://schemas.android.com/apk/res-auto"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/linearLayout">

                <android.support.v7.widget.RecyclerView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/scheduleListRecyclerView"
                    android:layout_centerHorizontal="true"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp" />

                <android.support.design.widget.FloatingActionButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom|right"
                    android:layout_margin="16dp"
                    app:layout_anchor="@id/scheduleListRecyclerView"
                    app:layout_anchorGravity="bottom|right|end"
                    app:layout_behavior="com.standart.trainschedule.FABScrollBehavior"
                    android:src="@drawable/abc_btn_rating_star_on_mtrl_alpha"
                    android:visibility="gone"
                    android:id="@+id/fab" />

                </android.support.design.widget.CoordinatorLayout>
            </RelativeLayout>
    </RelativeLayout>
</LinearLayout> 

问题是,如果我在手机上运行它,阴影不会出现,但在 Android Studio 的预览模式下,阴影会正确显示。如何解决?

最佳答案

在作为线性布局父级的相对布局中,您需要设置这两个属性:android:clipToPadding="false"android:paddingbottom="5dp"。不要对线性布局进行任何更改。

关于Android - 线性布局中的海拔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38934187/

相关文章:

android - 错误 : The constructor Geocoder (Context, Locale) is undefined

安卓日期和时间格式

android - Firebase 数据库 ArrayList 未排序

android - 是否可以获取已安装应用程序的用户名和密码?

android - 为什么 Android 应用程序在上市后体积越来越大?

Android水平LinearLayout在TextView中带有包装文本

android - GridView 不显示 wrap_content 高度线性布局中的所有项目

android - 如何使应用程序响应所有 Android 设备?

java - "The specified child already has a parent"添加新的 TableLayout

android - 在单独的 Activity 中显示绘制的 AChartEngine 图