【问题标题】:How to use a shape and selector at the same time for the background of a android layout element?如何同时使用形状和选择器作为 android 布局元素的背景?
【发布时间】:2012-03-06 07:34:17
【问题描述】:

我有两个 xml 文件。一个 xml 文件是 Shape,另一个是选择器。我的代码:

形状:

   <shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >

<stroke
    android:width="2dp"
    android:color="#33CCCC" />

<gradient
    android:angle="225"
    android:endColor="#DD33FF66"
    android:startColor="#DD000000" />

<corners
    android:bottomLeftRadius="7dp"
    android:bottomRightRadius="7dp"
    android:topLeftRadius="7dp"
    android:topRightRadius="7dp" />

选择器的xml文件包括:

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@drawable/panel_picture_frame_bg_focus_blue" />
<item android:state_pressed="true" android:drawable="@drawable/panel_picture_frame_bg_pressed_blue" />
<item android:drawable="@drawable/panel_picture_frame_bg_normal" />

我的主要问题是如何将这两个文件用作单个布局元素的背景。

【问题讨论】:

    标签: android android-layout background


    【解决方案1】:

    你不能同时使用两者作为背景,你应该把你的形状xml作为选择器的状态之一(例如你可以把它作为选择器的默认背景,@drawable/panel_picture_frame_bg_normaldrawable)。

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-29
    • 1970-01-01
    • 2011-11-28
    • 2011-11-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多