【发布时间】:2014-12-17 13:24:36
【问题描述】:
我正在尝试实现以下效果,这是一个看起来是浮动的圆圈:http://imgur.com/fjazcfa
为了实现这一点,我使用了两个ImageViews,每个都填充了一个可绘制的形状。圆圈ImageView 放置在阴影ImageView 的顶部,使圆圈看起来像是漂浮的。我的布局如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="56dp"
android:layout_height="56dp">
<ImageView
android:id="@+id/shadow_ImageView"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="@drawable/circle_shadow"
android:layout_centerInParent="true"/>
<ImageView
android:id="@+id/color_ImageView"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:src="@drawable/circle"/>
</RelativeLayout>
我的问题是,虽然两个 xml 形状可绘制对象都显示在布局预览中,但只有圆圈显示在实际设备上。以下是在设备上未显示的 circle_shadow 的定义:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size
android:width="48dp"
android:height="48dp"/>
<gradient
android:endColor="@color/clear"
android:startColor="@color/black"
android:type="radial"
android:gradientRadius="125%"/>
</shape>
以及在设备上显示的圆的定义:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/orange"/>
<size
android:width="40dp"
android:height="40dp"/>
</shape>
【问题讨论】:
标签: android android-layout android-imageview android-drawable