您好,我正在开发 android 应用程序,我试图在其中实现新的 Material 设计功能。我尝试应用高程属性,但它对我不起作用。我尝试了以下方式。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
tools:context="com.example.androidmaterialsamples.MainActivity" >
<ImageView
android:id="@+id/sampleImage"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/ic_launcher"
android:layout_centerInParent="true"
android:elevation="10dp"/>
</RelativeLayout>
它没有显示该图像的任何阴影。我做错了什么吗?需要一些帮助。谢谢。
我也尝试过这种方式,但输出仍然没有变化。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#0073ff" />
<corners android:radius="16dp" />
</shape>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
tools:context="com.example.androidmaterialsamples.MainActivity" >
<TextView
android:id="@+id/sampleImage"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="my name is nilesh"
android:padding="10dp"
android:textSize="20sp"
android:layout_centerInParent="true"
android:elevation="12dp"
android:background="@drawable/background"/>
</RelativeLayout>
最佳答案
您需要更改为 android:background 以显示阴影,而不是使用 android:src。
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="10dp"
android:background="@drawable/ic_launcher"/>
关于android - 高程属性不工作android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26923476/