相关疑难解决方法(0)

如何防止ListItem中的Button获得突出显示

所以我有自定义列表项,带有ListView按钮.按下时,按钮显示交替可绘制以向用户显示反馈.但是,当我点击该行时,每个按钮都显示按下状态,就像我点击它们一样.

如何让按钮显示其原始状态而不是state_pressed?

布局/列表项目:

<LinearLayout
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:orientation="horizontal"
    android:paddingBottom="10dp"
    android:paddingTop="10dp"
    android:descendantFocusability="blocksDescendants" >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:gravity="center_vertical|left" >

        <TextView
            android:id="@+id/txtMain"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:textAppearance="?android:attr/textAppearanceLarge"
            style="@style/PrimaryText" />

        <TextView
            android:id="@+id/txtSub"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:textAppearance="?android:attr/textAppearanceLarge"
            style="@style/SecondaryText" />
    </LinearLayout>

    <ImageButton
        android:id="@+id/imbResponse"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@null"
        android:focusable="false"
        android:duplicateParentState="false"
        android:src="@drawable/response_btn" 
        android:contentDescription="@string/response"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="5dp"
        android:layout_marginRight="10dp"
        android:layout_marginBottom="5dp" />
</LinearLayout> 
Run Code Online (Sandbox Code Playgroud)

绘制/ response_btn.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_focused="true" android:drawable="@drawable/res_m" />
    <item android:state_pressed="true" android:drawable="@drawable/res_m" />
    <item android:state_focused="false" android:state_pressed="false" android:drawable="@drawable/res_alt_m" />
</selector>
Run Code Online (Sandbox Code Playgroud)

我试图删除state_focused和state_pressed,state_focused.似乎该按钮从其父级获取state_pressed.

android listview listitem highlight

6
推荐指数
1
解决办法
3993
查看次数

Android:子视图从Jelly Bean中的父视图共享压缩状态

代码注释:1.RelativeLayout Clickable attr设置为true,其中有一个子视图,其Clickable attr设置为false.2.没有任何duplicateParentState attr,换句话说,duplicateParentState为false.3.子视图是TextView,其textColor是颜色选择器,因此它可以检查按下的状态.

行为:在level16之前,当单击RelativeLayout时,按下的状态不会传输到他的chlid视图.但是在16级或更高级别,它可以.

原因:setPressed ------> dispatchSetPressed ------>将压缩状态传递给子视图-----> childView.setPressed

15级的View.java onTouchEvent,

case MotionEvent.ACTION_DOWN:
                mHasPerformedLongPress = false;

                if (performButtonActionOnTouchDown(event)) {
                    break;
                }

                // Walk up the hierarchy to determine if we're inside a scrolling container.
                boolean isInScrollingContainer = isInScrollingContainer();

                // For views inside a scrolling container, delay the pressed feedback for
                // a short period in case this is a scroll.
                if (isInScrollingContainer) {
                    mPrivateFlags |= PREPRESSED;
                    if (mPendingCheckForTap == null) {
                        mPendingCheckForTap = new CheckForTap();
                    }
                    postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); …
Run Code Online (Sandbox Code Playgroud)

android view touch-event

5
推荐指数
0
解决办法
1641
查看次数

当不触摸时,Android SeekBar的状态变为按下状态

这是可能的布局xml:

<RelativeLayout
    android:id="@+id/seek_bar_wrapper"
    android:layout_width="match_parent"
    android:layout_height="200dip">

    <SeekBar
        android:id="@+id/seek_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_margin="20dip"
        android:maxHeight="2dip"
        android:minHeight="2dip"
        android:progressDrawable="@drawable/drawable_seekbar_progress"
        android:thumb="@drawable/drawable_seekbar_thumb" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

我将设置OnClickListenerRelativeLayout。奇怪的是,当我触摸时RelativeLayoutSeekBar就像按动它一样,当按下状态时,它的拇指成为可绘制对象。我认为状态变得紧迫。

这是一个错误,如何解决?

android android-view android-seekbar

4
推荐指数
2
解决办法
784
查看次数

单击ListView项目更改项目内元素的状态?

我不知道如何解释这个问题,但我会试试.我有一个包含几个项目的ListView.每个项目都有一个TextView和两个ImageView.我想在单击它们时更改ImageView,并且当我长按ListView项目时,我想打开上下文菜单.

对于ImageView,一切正常.对于整个项目,我可以在长按后显示上下文菜单,但我的问题是,当我按下TextView时,ImageView也会改变.

索莫的代码片段:

ListView项目:

     <TextView 
      android:id="@+id/title"
      android:textColor="@color/black"
      android:maxLines="2"
      android:textSize="14dip" 
            />
    <ImageView
        android:id="@+id/minus"
        android:src="@drawable/minusbutton"
        android:adjustViewBounds="true"
        android:gravity="center"
    />
    <ImageView 
        android:id="@+id/plus"
        android:src="@drawable/plusbutton"
        android:adjustViewBounds="true"
        android:gravity="center"
    />
Run Code Online (Sandbox Code Playgroud)

可绘制以更改加号按钮的状态:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false"
      android:drawable="@drawable/button_add_normal_disabled" />
<item android:state_enabled="true"
      android:state_pressed="true"
      android:drawable="@drawable/button_add_pressed" />
<item android:state_enabled="true"
      android:state_focused="true" 
      android:state_pressed="false" 
      android:drawable="@drawable/button_add_active" />
<item android:state_enabled="true"
      android:state_focused="false" 
      android:state_pressed="false"
      android:drawable="@drawable/button_add_normal" />
Run Code Online (Sandbox Code Playgroud)

我希望你理解我的问题.我认为一个观点的所有孩子都受到父母的一个事件的影响,但我不确定.

你有解决方案吗?提前致谢

events android listview click listviewitem

3
推荐指数
1
解决办法
4337
查看次数