当放置在 ViewFlipper 上时,ImageView 上的背景属性会被忽略
我有一个包含 FrameLayout 和两个视图的 Activity。第一个是 ViewFlipper,第二个是 ImageView。如果我注释掉 ViewFlipper,活动会正确渲染 ImageView 及其背景,但是当 ViewFlipper 可见时,ImageView 的背景将被完全忽略。
这是ViewFlipper的“功能”吗?有什么办法可以解决这个问题吗?
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/background_light"
>
<ViewFlipper android:id="@+id/flipper"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:flipInterval="5000"
>
<include layout="@layout/cell_1" android:id="@+id/cell_1"/>
<include layout="@layout/cell_2" android:id="@+id/cell_2"/>
<include layout="@layout/cell_3" android:id="@+id/cell_3"/>
</ViewFlipper>
<ImageView
android:background="@drawable/alpha_gradient_background"
android:id="@+id/statusIcon"
android:src="@drawable/status_icon"
android:padding="5dp"
android:layout_gravity="right"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:top="10dp"
android:right="10dp"
/>
</FrameLayout>
我的背景可绘制看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="3dp" android:color="#ffff0000" />
<gradient
android:startColor="#66660000"
android:centerColor="#66006600"
android:endColor="#66000066"
android:angle="270"
/>
</shape>
I have an Activity that contains a FrameLayout and two views. The first is a ViewFlipper and the second is an ImageView. If I comment out the ViewFlipper, the activity renders the ImageView and its background correctly, but when the ViewFlipper is visible, the ImageView's background is completely ignored.
Is this a "feature" of ViewFlipper? Is there a way I can work around this?
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/background_light"
>
<ViewFlipper android:id="@+id/flipper"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:flipInterval="5000"
>
<include layout="@layout/cell_1" android:id="@+id/cell_1"/>
<include layout="@layout/cell_2" android:id="@+id/cell_2"/>
<include layout="@layout/cell_3" android:id="@+id/cell_3"/>
</ViewFlipper>
<ImageView
android:background="@drawable/alpha_gradient_background"
android:id="@+id/statusIcon"
android:src="@drawable/status_icon"
android:padding="5dp"
android:layout_gravity="right"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:top="10dp"
android:right="10dp"
/>
</FrameLayout>
And my background drawable looks like this:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="3dp" android:color="#ffff0000" />
<gradient
android:startColor="#66660000"
android:centerColor="#66006600"
android:endColor="#66000066"
android:angle="270"
/>
</shape>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当按钮放置在 ViewFlipper 上时,按钮似乎能够渲染其背景。
因此,我通过创建部分透明的 PNG 并将其设置为按钮上的背景图像来解决这个问题。
It appears that Buttons are able to render their background when placed over a ViewFlipper.
I have therefore got around this by creating a partially transparent PNG and setting that as the background image on the button.