2016-07-18 14 views
0

Ich mache eine App, die ein großes PNG-Bild benötigt, um mit den oben auf dem Bild abgelegten Kontrollkästchen-Schaltflächen zu scrollen . Ich habe Hilfe von diesem Link Scrollview with many buttons over an image bekommen. Hier ist was ich bisher habe.Die Kontrollkästchen-Schaltflächen reagieren nicht richtig, wenn ein Scrollview verwendet wird, um durch eine große Bildansicht zu scrollen.

<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> 

Und hier ist die Aktivität:

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; 
} 

Das Problem ist, die Kontrollkästchen sind nicht richtig klicken. In der Tat funktionieren alle Tasten nicht. Ich gebe alle diese Knöpfe in die XML-Datei zu Testzwecken ein, um zu sehen, welche funktioniert und die einzige, die funktioniert, sind die Schalter. Der ganze Rest funktioniert nicht richtig, aber ich würde lieber Checkboxen als Schalter in meiner App bevorzugen. Jede Hilfe wird geschätzt! Vielen Dank.

Antwort

0

Ich löste mein Problem! Wenn ich diesen Code in meiner Aktivität benutze, ist das Drücken des Knopfes gelöst, aber auf Kosten des diagonalen Scrollens ist es etwas schwieriger für den Benutzer.

@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); 
}