大きな画像をスクロールしてスクロールして、スクロールする画像の上にチェックボックスボタンを置く必要のあるアプリを作っています。私はこのリンクScrollview with many buttons over an imageから助けを得ました。ここまで私がこれまで持っていたことがあります。Scrollviewを使用して大きな画像ビューをスクロールするときにチェックボックスのボタンが正しく反応しない
<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>
そして、ここでは、活動の:
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ファイルに入れて、どのボタンが動作し、スイッチだけが動作するかを確認します。すべての残りの部分は正常に動作しませんが、私は実際には私のアプリのスイッチではなくチェックボックスを優先します。どんな助けもありがとう!ありがとうございました。