Comment faire un Relativelayout cliquable?
J'ai une mise en page comme ceci
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:addStatesFromChildren="true"
android:clickable="true"
android:duplicateParentState="true"
android:focusable="true"
android:paddingBottom="10dip" >
<ImageView
android:id="@+id/imagView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:focusable="false"
android:background="@drawable/imageView_bg"
android:focusableInTouchMode="false" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="18dip"
android:background="@drawable/button_bg"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="left|center_vertical"
android:paddingLeft="25dip"
android:textColor="#ffffff"
android:textSize="20dip" />
</RelativeLayout>
button_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/btn_pressed"
android:state_pressed="true"/>
<item android:drawable="@drawable/btn_normal"/>
</selector>
imageView_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/img_pressed"
android:state_pressed="true"/>
<item android:drawable="@drawable/img_normal"/>
</selector>
L'affichage de l'image et le bouton a appuyé sur les images.lorsque l'utilisateur clique sur la vue ,veut appuyer sur les deux imageview et bouton(Montrant appuyé sur les images).Mais il ne montre pas pressé images. Comment atteindre cet objectif? Où est le problème?
Merci d'avance
- Avez-vous attacher un OnClickListener à votre RelativeLayout?
- sont-ils empilés les uns sur les autres ?
- remplacer l'affichage de l'image par une mise en page, dans laquelle vous mettez le bouton, et ajouter en double état parent du bouton
Vous devez vous connecter pour publier un commentaire.
android:clickable="true"
?Je pense qu'il résout le problème
Simple.Lieu RelativeLayout à l'intérieur de la FrameLayout.