Android RelativeLayout和OnClickListener
我找到了许多关于如何使相对布局响应单击事件的线索和答案。我已经根据他们实现了我的布局。但仍然没有调用侦听器。我还为它提供了选择器,它工作得很好 我的列表项目xml:Android RelativeLayout和OnClickListener,android,android-linearlayout,onclicklistener,Android,Android Linearlayout,Onclicklistener,我找到了许多关于如何使相对布局响应单击事件的线索和答案。我已经根据他们实现了我的布局。但仍然没有调用侦听器。我还为它提供了选择器,它工作得很好 我的列表项目xml: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/re
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/air.com.jingit.mobile"
android:layout_width="match_parent" android:layout_height="@dimen/actionBarHeight"
android:clickable="true"
android:background="@drawable/my_list_selector">
<com.loopj.android.image.SmartImageView
android:layout_width="@dimen/actionBarHeight"
android:layout_height="@dimen/actionBarHeight"
android:id="@+id/image"
android:scaleType="fitCenter"
android:layout_marginLeft="20dp"
android:clickable="false"
android:focusable="false"/>
<com.uma.mobile.view.CustomTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Loading..."
android:id="@+id/userName"
app:typeface="fonts/HelveticaNeue"
app:customStyle="Regular"
android:textSize="20sp"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/image"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:textColor="#000"
android:clickable="false"
android:focusable="false"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#aaa"
android:layout_alignBottom="@+id/image"></FrameLayout>
编辑1:
该相对布局被添加到滚动视图内部的线性布局中,因此其工作方式类似于列表视图。这有什么关系吗
list_view.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:background="#eee">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/scrollView" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/listContainer" />
</ScrollView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:layout_centerHorizontal="true"
android:src="@drawable/up_indicator"
android:layout_alignBottom="@+id/scrollView" />
< P> >我有一个<代码> RealValayOut[<代码> >不开机>代码> OnCase事件,这是因为我中间有一个<代码>按钮<代码>,而<代码>按钮/代码>的OnCurk事件正在被触发,而不是<代码> RealValayOut一个。解决了这一问题,为他们两个都实现了侦听器:
OnClickListener listener = new OnClickListener() {
public void onClick(View v) {
//Handle onClick
}
};
relativeLayout.setOnClickListener(listener);
button.setOnClickListener(listener);
希望有帮助 在您的
RelativeLayout java类中添加OnClickListener
使用android:clickable=“true”
而不是android:clickable=“false”
使布局可点击使用视图。setOnClickListener@Homosapiens即使这样也不起作用。@ρц∑ρєK我给了安卓android:clickable=“true”
对于布局@ρρєK,我已编辑了问题。你知道吗?
OnClickListener listener = new OnClickListener() {
public void onClick(View v) {
//Handle onClick
}
};
relativeLayout.setOnClickListener(listener);
button.setOnClickListener(listener);