1

我有这个相对布局:

<RelativeLayout
    android:id="@+id/relativeLayout5"
    android:layout_width="fill_parent"
    android:layout_height="110dp"
    android:layout_below="@+id/relativeLayout4"
    android:background="@drawable/pigs_banner_selector"
    android:clickable="true"
    >
    <ImageView
        android:id="@+id/imageView9"
        android:layout_width="220dp"
        android:layout_height="60dp"
        android:layout_marginTop="60dp"
        android:layout_marginLeft="0dp"
        android:layout_marginBottom="-10dp"
        android:src="@drawable/banner_games_pighunt_hill" />
    <TextView
        android:id="@+id/textView3"
        android:fontFamily="sans-serif-condensed"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/gluecksschweinjagd"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="@color/white"
        android:textSize="31sp"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="6dp"
        android:textStyle="bold" />
</RelativeLayout>

和RelativeLayout的选择器:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_focused="true" android:drawable="@color/white"/>
    <item android:state_pressed="true" android:drawable="@color/highlight_pigs_banner" />
    <item android:drawable="@color/pigs_banner"/>
</selector>

行为是这样的:relativeLayout 按预期改变它的颜色。但我希望子元素(ImageView)也能获得选择器的颜色(@color/highlight_pigs_banner)。

编辑: 颜色 highlight_pigs_banner 基本上将 alpha 值放在颜色上。我怎样才能在imageview(子元素)上实现这一点,仍然只点击RelativeLayout

我尝试添加android:clickable="true"到子元素,这不起作用,以及android:addStatesFromChildren="true"给我一个stackoverflow异常的relativeLayout。任何人都知道如何实现这一目标?谢谢。

4

1 回答 1

0

您也应该使用 SelectorImageViewTextView

<TextView android:id="@+id/textView3" 
          android:fontFamily="sans-serif-condensed"
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content"
          android:textColor="@drawable/text_selector" />

text_selector.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="false" 
          android:state_pressed="false" 
          android:color="@color/normal"/>
    <item android:state_pressed="true" 
          android:color="@drawable/highlight"/>
    <item android:state_selected="true" 
          android:state_pressed="false" 
          android:color="@drawable/highlight"/>
</selector> 

颜色.xml

 <drawable name="highlight">#ff590d</drawable>
于 2013-05-29T07:07:46.017 回答