Answer the question
In order to leave comments, you need to log in
How to prevent state_pressed from propagating to LinearLayout child?
Given a ListView. Each item of this ListView contains:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fl_item"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/back_list_item"
>
<LinearLayout
android:layout_width="0dip" android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical"
android:paddingRight="5dip"
android:paddingLeft="5dip"
android:paddingBottom="5dip"
>
<TextView android:id="@+id/tv_title"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:singleLine="false"
android:layout_weight="1"
android:text="Lenovo A 1000"
android:textSize="14sp"
android:textStyle="normal"
android:maxLines="3"
/>
</LinearLayout>
<ImageView android:id="@+id/toBasketImageView"
android:layout_width="wrap_content" android:layout_height="fill_parent"
android:scaleType="fitCenter"
android:src="@drawable/item_add_to_basket"
/>
</LinearLayout>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/to_basket_2_white" />
<item android:state_pressed="false" android:drawable="@drawable/to_basket_1_white" />
</selector>
Answer the question
In order to leave comments, you need to log in
if still relevant, then one of the options is
to write your own components
for example.
package widgets;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
public class ImageViewEx extends ImageView {
public ImageViewEx(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
@Override
public void setPressed(boolean pressed) {
if (pressed && getParent() instanceof View && ((View) getParent()).isPressed()) {
return;
}
super.setPressed(pressed);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question