2013-04-23 16 views
2

我对我的ListView行自定义视图使用以下布局。我怎样才能让ListView的行中的一个子线性布局在点击时不突出显示

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:duplicateParentState="false" 
     android:clickable="false"  
     android:id="@+id/header" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" > 
     <!-- A lot of text views --> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal"  
     android:minHeight="48dp" > 
     <!-- A lot of text views --> 
    </LinearLayout> 

</LinearLayout> 

通过使用android:duplicateParentState="false"android:clickable="false",我期待的header的LinearLayout被点击列表视图排时就不会突出显示。

但是,它仍然被强调。我可否知道我怎样才能让header LinearLayout不突出显示?以除去视觉亮点

回答

2

的一种方式是改变header的背景绘制到StateListDrawable具有用于所有相关的状态,例如state_pressed并且没有可绘制的相同(例如,固体的颜色)。

0

将您的标题视图分离为新的xml。然后在你的活动/片段中膨胀这个视图并且在其上调用addHeaderView(view, null, false);(第三个参数是boolean isSelectable)。

LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
View header = inflater.inflate(R.layout.header, null,false); 
getListView().addHeaderView(view, null, false); 
+0

这不是标题视图。虽然它的id被命名为“header”,但它可以出现在单个列表视图中的多行中。 – 2013-04-23 09:13:34

+0

啊哈,对不起,我看错了。您是否尝试过@laalto建议的解决方案?这应该工作。 – traninho 2013-04-23 09:19:58

相关问题