Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
297 views
in Technique[技术] by (71.8m points)

"android:elevation=" doesn't work on devices pre-Lollipop with compile API21

I'm trying to use "android: elevation =" in my application but once I run it does not appear in the device with android 4.1.2

gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.example.alvaro.proyectocaronte"
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
}

layout.xml

<RelativeLayout
                android:layout_width="1100dp"
                android:layout_height="fill_parent"
                android:background="@drawable/rounded_corner"
                android:layout_alignParentTop="true"
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true"
                android:layout_marginRight="93dp"
                android:layout_marginEnd="93dp"
                android:elevation="3dp"/>

maybe I'm not compiling correctly Lollipop for pre-lollipop devices, Any suggestions?

If you need to see other parts of the code, I'll edit the question

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

UPDATED ::

  1. Best Practice to do that is

    <android.support.v7.widget.CardView>
        <YourLayout>
    </android.support.v7.widget.CardView>
    

    and add library for cardview

    dependencies {
       ...
       compile 'com.android.support:cardview-v7:21.0.+'
     }
    
  2. On Pre-Lollipop you can use this drawable

    android:background="@android:drawable/dialog_holo_light_frame"

    it will give you the look of elevation

  3. you can create your own like this

    <?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="#BDBDBD"/>
        <corners android:radius="5dp"/>
    </shape>
    </item>
    
    <item
    android:left="0dp"
    android:right="0dp"
    android:top="0dp"
    android:bottom="2dp">
    <shape android:shape="rectangle">
        <solid android:color="#ffffff"/>
        <corners android:radius="5dp"/>
    </shape>
    </item>
    </layer-list>
    

reference


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...