我的滚动视图包含Linearlayout
个孩子,而linearlayout
有一个drawingview
。
问题:我尝试了几乎所有关于这个主题的可用答案,但没有一个工作,我不明白为什么不点击(scrollview,线性布局甚至绘图视图)。
注意:我尝试点击三者中的每一个都没有效果。
xml代码:
<ScrollView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@id/scrollview"
android:clickable="true"
>
<LinearLayout
android:setorientation="vertical"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@id/linear"
android:clickable="false">
<Customview
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@id/draw"
android:clickable="false"/>
</LinearLayout>
</ScrollView>
答案 0 :(得分:0)
你已经设置了android:clickable =“false”,两者都是真的,它会对你有用
<ScrollView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@id/scrollview"
android:clickable="true"
>
<LinearLayout
android:setorientation="vertical"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@id/linear"
android:clickable="true">
<Customview
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@id/draw"
android:clickable="true"/>
</LinearLayout>
</ScrollView>
答案 1 :(得分:0)
首先,ScrollView
,layout_height
被包裹!对于你给match_parent
的孩子,我怀疑你的观点甚至不会显示出来。不是吗?
然后不知道为什么使用setorientation
和android:id="@id/draw"
代替android:orientation
和android:id="@+id
如果要检查滚动工作,请使用
scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
@Override
public void onScrollChanged() {
Log.d("TAG", "onScrollChanged: ");
// DO SOMETHING WITH THE SCROLL COORDINATES
}
});
您正在使用不必要的属性检查此示例:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#8768"
android:orientation="vertical">
<ScrollView
android:id="@+id/scrollIndicatorDown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#823">
<LinearLayout
android:id="@+id/first_child"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#900"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linear_layout"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#000"
android:orientation="vertical"></LinearLayout>
<LinearLayout
android:id="@+id/web_view"
android:layout_width="match_parent"
android:layout_height="500dp"
android:background="#987"
android:orientation="vertical"></LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
如果您为onClickListner
写了一个linear_layout
,它就能正常工作!
回答:您ScrollView
的子视图正在消耗您在ScrollView
上执行的点击事件。
此问题的解决方案是将onClickLIstener
设置为ScrollView
(它的孩子)的直接子项。
所以根据我的例子,如果我想找出ScrollView
onClick,我会把我的听众写给它的孩子。
scrolChild =(LinearLayout) findViewById(R.id.first_child) ;
scrolChild .setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(YourActivityName.this, "You Clicked Me OH yeaaaaa", Toast.LENGTH_SHORT).show();
}
});
当您需要androidclickable-true android:clickable="true" mean's that it's not clickable?
时请阅读此处这是我的活动
public class MainActivity extends AppCompatActivity {
private ScrollView scrollView;
private LinearLayout scroolChild;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.web);
scrollView = (ScrollView) findViewById(R.id.scrollIndicatorDown);
scroolChild =(LinearLayout) findViewById(R.id.first_child) ;
scroolChild.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "You Clicked Me OH yeaaaaa", Toast.LENGTH_SHORT).show();
}
});
scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
@Override
public void onScrollChanged() {
Log.d("TAG", "GotAScrollChanged: ");
// DO SOMETHING WITH THE SCROLL COORDINATES
}
});
}
}