首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >StateList为父视图工作,但不为子视图工作

StateList为父视图工作,但不为子视图工作
EN

Stack Overflow用户
提问于 2012-12-10 19:13:45
回答 1查看 73关注 0票数 0

我在android UI中使用StateList为视图的不同状态显示不同的绘图。

这是代码。问题是,当我在第一个LinearLayout上放置android:background="@drawable/state_list"时,它会突出显示“已按下”事件的状态。

但是如果我将相同的StateList连接到第二个LinearLayout,它就不能工作了。

代码语言:javascript
复制
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:paddingBottom="5dp"
    android:background="@drawable/highlight_states">     // this WORKS!

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="horizontal"
        android:background="@drawable/highlight_states">    // this DOES NOT WORK.

        <ImageButton
            android:id="@+id/profile_call_button"
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:layout_gravity="center"
            android:background="@color/transparent"
            android:scaleType="fitCenter"
            android:src="@drawable/icon_phone_green" />
   </LinearLayout>
</LinearLayout>

下面是我使用的StateList的代码。highlight_states.xml

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/selected_textbox" /> <!-- pressed -->
    <item android:state_focused="true" android:drawable="@drawable/highlight_pressed" /> <!-- focused -->    
</selector>
EN

回答 1

Stack Overflow用户

发布于 2013-06-07 15:16:03

在子LinearLayout上设置

代码语言:javascript
复制
android:duplicateParentState="true"
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13799840

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档