Android ScrollView内部的可单击线性布局不';不要一点一点地开枪
我有以下问题。在我的布局中,我有一个带有Android ScrollView内部的可单击线性布局不';不要一点一点地开枪,android,android-layout,android-scrollview,Android,Android Layout,Android Scrollview,我有以下问题。在我的布局中,我有一个带有fillViewport=“true”的滚动视图。在里面,我有一个可点击的线性布局(里面依次有4个视图)。我的ScrollView似乎截取了LinearLayout的onClick。我的代码是: <ScrollView android:id="@+id/signup_scrollview" android:layout_marginTop="56dp" android:layout_width="wrap_content"
fillViewport=“true”
的滚动视图。在里面,我有一个可点击的线性布局(里面依次有4个视图)。我的ScrollView似乎截取了LinearLayout的onClick。我的代码是:
<ScrollView
android:id="@+id/signup_scrollview"
android:layout_marginTop="56dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:clickable="false"
android:fillViewport="true">
....
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar_actionbar">
....
<LinearLayout
android:id="@+id/add_product_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="horizontal">
....
</LinearLayout>
</RelativeLayout>
</ScrollView>
....
....
....
我已经尝试在InterceptTouchEvent(MotionEvent e)上实现一个
;在我看来,但没有用。有人能指导我如何点燃我的线性布局的onClick吗?谢谢。您已禁用了根标记中的click,请参阅
中的android:clickable=“false”
,这是您无法使线性布局成为可单击的
从
将android:clickable=“true”
添加到LinearLayout
及
layout.setClickable(真)代码>在java文件中。只需将其写入内部线性布局标记中即可
android:onClick="onClick"
在java代码中
public void onClick(View v) {
if(v.getId()==R.id.add_product_button){
// do your code here
System.out.println("Layout click");
}
}
尝试将android:genderantfocusability=“blocksDescendants”
放在根布局上。将android:genderantfocusability=“blocksDescendants”
添加到根布局没有用……我仍然无法单击我的线性布局。我曾尝试在根元素的clickable、focusable和FocusableInTouch模式中设置true/false,但没有成功。@rion18您不需要在任何地方编写clickable或focusable,只需在android:clickable=“true”
内部LinearLayout
中编写yourLayout.setClickable(true)代码>在你的activity.java文件中,我已经尝试过了,但没有成功。我的ScrollView仍在拦截单击…出于某种原因,将onClick侦听器显式设置为这样是唯一有效的方法。谢谢!