使用 Scrollview 滚动浏览大型 Imageview 时,复选框按钮无法正确响应
Checkbox buttons aren't responding properly when using a Scrollview to scroll through a large Imageview
我正在制作一个应用程序,它需要一个大的 png 图像才能滚动,而复选框按钮位于将随图像滚动的图像顶部。我从这个 link 得到了帮助。这是我目前所拥有的。
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/svVertical"
android:layout_below="@+id/buildingNameText"
android:layout_alignParentStart="true"
android:layout_marginBottom="60dp" >
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/hsvHorizontal" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isScrollContainer="true">
<ImageView
android:id="@+id/map_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/dummy_floor_extra_large"
android:scaleType="centerCrop"/>
<CheckBox
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/checkBox"
android:button="@null"
android:background="?android:attr/listChoiceIndicatorMultiple"
android:layout_marginStart="21dp"
android:backgroundTint="#22e300"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginTop="15dp" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/checkBox2"
android:layout_below="@+id/checkBox"
android:layout_alignStart="@+id/checkBox"
android:layout_marginStart="8dp"
android:buttonTint="#22e300" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioButton"
android:layout_below="@+id/checkBox2"
android:layout_alignStart="@+id/checkBox2"
android:layout_marginTop="7dp"
android:buttonTint="#22e300" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New RadioButton"
android:id="@+id/radioButton2"
android:layout_below="@+id/radioButton"
android:layout_toEndOf="@+id/checkBox"
android:layout_marginStart="150dp"
android:layout_marginTop="58dp" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New CheckBox"
android:id="@+id/checkBox3"
android:layout_below="@+id/radioButton2"
android:layout_alignStart="@+id/radioButton2"
android:layout_marginTop="32dp" />
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Switch"
android:id="@+id/switch1"
android:layout_below="@+id/checkBox3"
android:layout_alignStart="@+id/checkBox3"
android:layout_marginTop="42dp" />
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/switch2"
android:layout_below="@+id/radioButton"
android:layout_marginTop="7dp"
android:layout_alignStart="@+id/radioButton" />
<Button
android:layout_width="50dp"
android:layout_height="45dp"
android:id="@+id/button"
android:layout_above="@+id/checkBox3"
android:layout_toStartOf="@+id/radioButton2" />
</RelativeLayout>
</HorizontalScrollView>
</ScrollView>
这里是 activity:
private ScrollView scrollY;
private HorizontalScrollView scrollYChild;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_floor_view);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.parseColor("#505050"));
}
scrollY = (ScrollView) findViewById(R.id.svVertical);
scrollYChild = (HorizontalScrollView) findViewById(R.id.hsvHorizontal);
}
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
scrollYChild.dispatchTouchEvent(event);
scrollY.onTouchEvent(event);
return true;
}
问题是复选框没有正确点击。事实上,所有的按钮都不起作用。我将所有这些按钮都放在 xml 文件中以进行测试,以查看哪个有效,唯一有效的是开关。其余的都不能正常工作,但我真的更喜欢复选框而不是我的应用程序中的开关。任何帮助表示赞赏!谢谢。
我的问题解决了!如果我在我的 activity 中使用这段代码,按钮按下问题就解决了,但代价是对角线滚动对用户来说有点困难。
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
scrollYChild.onTouchEvent(event);
return super.dispatchTouchEvent(event);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
scrollYChild.onTouchEvent(event);
scrollY.onTouchEvent(event);
return super.onTouchEvent(event);
}
我正在制作一个应用程序,它需要一个大的 png 图像才能滚动,而复选框按钮位于将随图像滚动的图像顶部。我从这个 link
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/svVertical"
android:layout_below="@+id/buildingNameText"
android:layout_alignParentStart="true"
android:layout_marginBottom="60dp" >
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/hsvHorizontal" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isScrollContainer="true">
<ImageView
android:id="@+id/map_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/dummy_floor_extra_large"
android:scaleType="centerCrop"/>
<CheckBox
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/checkBox"
android:button="@null"
android:background="?android:attr/listChoiceIndicatorMultiple"
android:layout_marginStart="21dp"
android:backgroundTint="#22e300"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginTop="15dp" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/checkBox2"
android:layout_below="@+id/checkBox"
android:layout_alignStart="@+id/checkBox"
android:layout_marginStart="8dp"
android:buttonTint="#22e300" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioButton"
android:layout_below="@+id/checkBox2"
android:layout_alignStart="@+id/checkBox2"
android:layout_marginTop="7dp"
android:buttonTint="#22e300" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New RadioButton"
android:id="@+id/radioButton2"
android:layout_below="@+id/radioButton"
android:layout_toEndOf="@+id/checkBox"
android:layout_marginStart="150dp"
android:layout_marginTop="58dp" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New CheckBox"
android:id="@+id/checkBox3"
android:layout_below="@+id/radioButton2"
android:layout_alignStart="@+id/radioButton2"
android:layout_marginTop="32dp" />
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Switch"
android:id="@+id/switch1"
android:layout_below="@+id/checkBox3"
android:layout_alignStart="@+id/checkBox3"
android:layout_marginTop="42dp" />
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/switch2"
android:layout_below="@+id/radioButton"
android:layout_marginTop="7dp"
android:layout_alignStart="@+id/radioButton" />
<Button
android:layout_width="50dp"
android:layout_height="45dp"
android:id="@+id/button"
android:layout_above="@+id/checkBox3"
android:layout_toStartOf="@+id/radioButton2" />
</RelativeLayout>
</HorizontalScrollView>
</ScrollView>
这里是 activity:
private ScrollView scrollY;
private HorizontalScrollView scrollYChild;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_floor_view);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.parseColor("#505050"));
}
scrollY = (ScrollView) findViewById(R.id.svVertical);
scrollYChild = (HorizontalScrollView) findViewById(R.id.hsvHorizontal);
}
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
scrollYChild.dispatchTouchEvent(event);
scrollY.onTouchEvent(event);
return true;
}
问题是复选框没有正确点击。事实上,所有的按钮都不起作用。我将所有这些按钮都放在 xml 文件中以进行测试,以查看哪个有效,唯一有效的是开关。其余的都不能正常工作,但我真的更喜欢复选框而不是我的应用程序中的开关。任何帮助表示赞赏!谢谢。
我的问题解决了!如果我在我的 activity 中使用这段代码,按钮按下问题就解决了,但代价是对角线滚动对用户来说有点困难。
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
scrollYChild.onTouchEvent(event);
return super.dispatchTouchEvent(event);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
scrollYChild.onTouchEvent(event);
scrollY.onTouchEvent(event);
return super.onTouchEvent(event);
}