2012-04-02 16 views
2

Ich habe ein relatives Layout mit einem anderen relate laout darin und dann einen scrollview mit einem anderen relativen Layout, das Buttons in fast einem List Type Layout enthält. Es funktioniert gut, aber ich habe jetzt ein Problem. Wenn ich es auf meinem Gerät teste und versuche es zu scrollen, scrollt es nicht, sondern initialisiert das Ontouch auf den Tasten und scrollt nicht. Es ist so, als würden die Schaltflächen den Bildlauf überschreiben? Ich habe alles versucht. Wenn ich eine Schaltfläche in der ersten relativen Ansicht außerhalb der Bildlaufleiste plaziere, wird der gesamte Bildschirm für die erste Schaltfläche in der Bildlaufansicht aktiviert. Bitte helfen Sie?Android Scrollview und RelativeLayout Buttons mit onTouch

Wie ich schon sagte, ich habe versucht, die relativ Layouts linears usw. zu ändern, ohne Erfolg

hier ist meine Klasse:

package com.pod3d.locatesa; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.MotionEvent; 
import android.view.View; 
import android.view.View.OnTouchListener; 
import android.widget.Button; 

public class Categories extends Activity implements OnTouchListener{ 
Button Button01,Button02,Button03,Button04,Button05,Button06, 
Button07,Button08,Button09,Button10,Button11,Button12,home; 


@Override 
public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.categories); 
      Button01 = (Button) findViewById(R.id.Button01); 
      Button02 = (Button) findViewById(R.id.Button02); 
      Button03 = (Button) findViewById(R.id.Button03); 
      Button04 = (Button) findViewById(R.id.Button04); 
      Button05 = (Button) findViewById(R.id.Button05); 
      Button06 = (Button) findViewById(R.id.Button06); 
      Button07 = (Button) findViewById(R.id.Button07); 
      Button08 = (Button) findViewById(R.id.Button08); 
      Button09 = (Button) findViewById(R.id.Button09); 
      Button10 = (Button) findViewById(R.id.Button10); 
      Button11 = (Button) findViewById(R.id.Button11); 
      Button12 = (Button) findViewById(R.id.Button12); 




    Button01.setOnTouchListener(this); 
    Button02.setOnTouchListener(this); 
    Button03.setOnTouchListener(this); 
    Button04.setOnTouchListener(this); 
    Button05.setOnTouchListener(this); 
    Button06.setOnTouchListener(this); 
    Button07.setOnTouchListener(this); 
    Button08.setOnTouchListener(this); 
    Button09.setOnTouchListener(this); 
    Button10.setOnTouchListener(this); 
    Button11.setOnTouchListener(this); 
    Button12.setOnTouchListener(this); 


} 

@Override 

public boolean onTouch(View view, MotionEvent event) { 
    switch(event.getAction()){ 
    case MotionEvent.ACTION_DOWN: 
    case R.id.Button01 : 
     Intent myIntent = new Intent(view.getContext(), Emergencies.class); 
     startActivity(myIntent); 
     break; 
    case R.id.Button02 : 
     Intent myIntent01 = new Intent(view.getContext(), TouristAttractions.class); 
     startActivity(myIntent01); 
     break; 
    case R.id.Button03 : 
     Intent myIntent02 = new Intent(view.getContext(), Accommodation.class); 
     startActivity(myIntent02); 
     break; 
    case R.id.Button04 : 
     Intent myIntent03 = new Intent(view.getContext(), Tourism_info.class); 
     startActivity(myIntent03); 
     break; 
    case R.id.Button05 : 
     Intent myIntent04 = new Intent(view.getContext(), Shopping.class); 
     startActivity(myIntent04); 
     break; 
    case R.id.Button06 : 
     Intent myIntent05 = new Intent(view.getContext(), Leisure.class); 
     startActivity(myIntent05); 
     break; 
    case R.id.Button07 : 
     Intent myIntent06 = new Intent(view.getContext(), Transport.class); 
     startActivity(myIntent06); 
     break; 
    case R.id.Button08 : 
     Intent myIntent07 = new Intent(view.getContext(), Fuel.class); 
     startActivity(myIntent07); 
     break; 
    case R.id.Button09 : 
     Intent myIntent08 = new Intent(view.getContext(), Events.class); 
     startActivity(myIntent08); 
     break; 
    case R.id.Button10 : 
     Intent myIntent09 = new Intent(view.getContext(), Banking.class); 
     startActivity(myIntent09); 
     break; 
    case R.id.Button11 : 
     Intent myIntent10 = new Intent(view.getContext(), Businesses.class); 
     startActivity(myIntent10); 
     break; 
    case R.id.Button12 : 
     Intent myIntent11 = new Intent(view.getContext(), Dining.class); 
     startActivity(myIntent11); 
     break; 

    } 
    return false; 


} 



} 

Hier mein Layout xml ist:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 

<RelativeLayout 
    android:id="@+id/relativeLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentTop="true" 
    android:background="@drawable/action" > 

    <Button 
     android:id="@+id/home" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     android:layout_marginRight="5dp" 
     android:background="@drawable/home" android:text="@string/button_home"/> 
</RelativeLayout> 




<ScrollView 
    android:id="@+id/scrollview1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_below="@+id/relativeLayout1" android:isScrollContainer="true"> 

    <LinearLayout 
     android:id="@+id/relativeLayout2" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="fill_vertical" 
     android:orientation="vertical" > 

     <Button 
      android:id="@+id/Button01" 
      android:layout_width="fill_parent" 
      android:layout_height="45dp" 
      android:layout_marginTop="5dp" 
      android:background="@drawable/action" 
      android:text="@string/button_emergency" 
      android:textColor="#cccccc" 
      android:textSize="20dp" /> 

     <Button 
      android:id="@+id/Button02" 
      android:layout_width="fill_parent" 
      android:layout_height="45dp" 
      android:layout_marginTop="5dp" 
      android:background="@drawable/action" 
      android:text="@string/button_tourist_int" 
      android:textColor="#cccccc" 
      android:textSize="20dp" /> 

     <Button 
      android:id="@+id/Button03" 
      android:layout_width="fill_parent" 
      android:layout_height="45dp" 
      android:layout_marginTop="5dp" 
      android:background="@drawable/action" 
      android:text="@string/button_accommodation" 
      android:textColor="#cccccc" 
      android:textSize="20dp" /> 

     <Button 
      android:id="@+id/Button04" 
      android:layout_width="fill_parent" 
      android:layout_height="45dp" 
      android:layout_marginTop="5dp" 
      android:background="@drawable/action" 
      android:text="@string/button_tousisminfo" 
      android:textColor="#cccccc" 
      android:textSize="20dp" /> 

     <Button 
      android:id="@+id/Button05" 
      android:layout_width="fill_parent" 
      android:layout_height="45dp" 
      android:layout_marginTop="5dp" 
      android:background="@drawable/action" 
      android:text="@string/button_shopping" 
      android:textColor="#cccccc" 
      android:textSize="20dp" /> 

     <Button 
      android:id="@+id/Button06" 
      android:layout_width="fill_parent" 
      android:layout_height="45dp" 
      android:layout_marginTop="5dp" 
      android:background="@drawable/action" 
      android:text="@string/button_leisure" 
      android:textColor="#cccccc" 
      android:textSize="20dp" /> 

     <Button 
      android:id="@+id/Button07" 
      android:layout_width="fill_parent" 
      android:layout_height="45dp" 
      android:layout_marginTop="5dp" 
      android:background="@drawable/action" 
      android:text="@string/button_transport" 
      android:textColor="#cccccc" 
      android:textSize="20dp" /> 

     <Button 
      android:id="@+id/Button08" 
      android:layout_width="fill_parent" 
      android:layout_height="45dp" 
      android:layout_marginTop="5dp" 
      android:background="@drawable/action" 
      android:text="@string/button_fuel" 
      android:textColor="#cccccc" 
      android:textSize="20dp" /> 

     <Button 
      android:id="@+id/Button09" 
      android:layout_width="fill_parent" 
      android:layout_height="45dp" 
      android:layout_marginTop="5dp" 
      android:background="@drawable/action" 
      android:text="@string/button_events" 
      android:textColor="#cccccc" 
      android:textSize="20dp" /> 

     <Button 
      android:id="@+id/Button10" 
      android:layout_width="fill_parent" 
      android:layout_height="45dp" 
      android:layout_marginTop="5dp" 
      android:background="@drawable/action" 
      android:text="@string/button_banking" 
      android:textColor="#cccccc" 
      android:textSize="20dp" /> 

     <Button 
      android:id="@+id/Button11" 
      android:layout_width="fill_parent" 
      android:layout_height="45dp" 
      android:layout_marginTop="5dp" 
      android:background="@drawable/action" 
      android:text="@string/button_businesses" 
      android:textColor="#cccccc" 
      android:textSize="20dp" /> 

     <Button 
      android:id="@+id/Button12" 
      android:layout_width="fill_parent" 
      android:layout_height="45dp" 
      android:layout_marginTop="5dp" 
      android:background="@drawable/action" 
      android:text="@string/button_dining" 
      android:textColor="#cccccc" 
      android:textSize="20dp" /> 
    </LinearLayout> 
</ScrollView> 

</RelativeLayout> 

Und hier ist mein Manifest:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
android:versionCode="3" 
android:versionName="3.5.1" package="com.pod3d.locatesa" 
android:installLocation="preferExternal"> 

<!-- The application must be compiled using Google APIs (Android 3.0) --> 
<!-- However, target and min SDK can be 8 (Android 2.2) --> 
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8"/> 

<uses-permission android:name="android.permission.CAMERA" /> 
<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
<uses-permission android:name="android.permission.ACCESS_SURFACE_FLINGER" /> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 
<uses-permission android:name="android.permission.READ_PHONE_STATE"/> 
<uses-permission android:name="android.permission.WAKE_LOCK"/> 
<uses-feature android:name="android.hardware.camera" android:required="false"/> 
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/> 
<uses-feature android:name="android.hardware.location.gps" android:required="false"/> 
<uses-feature android:name="android.hardware.sensor.accelerometer" android:required="false"/> 
<uses-feature android:name="android.hardware.sensor.compass" android:required="false"/> 
<uses-feature android:glEsVersion="0x00020000" android:required="true" /> 

<application 
    android:label="@string/app_name" 
    android:icon="@drawable/icon" 
    android:debuggable="true"> 

    <uses-library android:name="com.google.android.maps" /> 

    <activity android:name=".Landing"    
       android:screenOrientation="portrait" 
       android:label="@string/app_name"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 


    <activity android:name=".Categories" 
       android:screenOrientation="portrait" 
       > 

    </activity> 

    <activity android:name=".Emergencies" 
       android:screenOrientation="portrait" 
      > 

    </activity> 

    <activity android:name=".Dining" 
       android:screenOrientation="portrait" 
      > 

    </activity> 

    <activity android:name=".Leisure" 
       android:screenOrientation="portrait" 
       > 

    </activity> 

    <activity android:name=".Shopping" 
       android:screenOrientation="portrait" 
      > 

    </activity> 

    <activity android:name=".TourismInfo" 
       android:screenOrientation="portrait" 
      > 

    </activity> 

    <activity android:name=".TouristAttractions" 
       android:screenOrientation="portrait" 
      > 

    </activity> 

    <activity android:name=".Transport" 
       android:screenOrientation="portrait" 
      > 

    </activity> 

    <activity android:name=".Fuel" 
       android:screenOrientation="portrait" 
      > 

    </activity> 

    <activity android:name=".Events" 
       android:screenOrientation="portrait" 
      > 

    </activity> 

    <activity android:name=".Banking" 
       android:screenOrientation="portrait" 
      > 

    </activity> 

    <activity android:name=".Businesses" 
       android:screenOrientation="portrait" 
      > 

    </activity> 

    <activity android:name=".Hospitals" 
       android:screenOrientation="portrait" 
      > 
      </activity> 

     <activity android:name=".Fire" 
       android:screenOrientation="portrait" 
      ></activity> 

      <activity android:name=".Police" 
       android:screenOrientation="portrait" 
      ></activity> 

       <activity android:name=".Tourism_info" 
       android:screenOrientation="portrait" 
      ></activity> 

       <activity android:name=".Animal" 
       android:screenOrientation="portrait" 
      ></activity> 



    <!-- Start screen --> 
    <activity android:name=".SplashActivity" 
       android:theme="@style/Theme.Fullscreen" 
       android:screenOrientation="portrait" 
       android:label="@string/app_name">   
    </activity> 

    <!-- junaio AR view activity --> 
    <activity 
     android:name=".JunaioARViewTestActivity" 
     android:theme="@style/Theme.Fullscreen" 
     android:configChanges="orientation" 
     android:screenOrientation="landscape"> 
    </activity> 

    <activity 
     android:name="com.metaio.junaio.plugin.view.POIDetailDialog" 
     android:theme="@style/Theme.POIDialog" 
     android:screenOrientation="landscape"> 
    </activity> 

    <activity 
     android:name="com.metaio.junaio.plugin.view.WebViewActivity" 
     android:theme="@style/Theme.Fullscreen" 
     android:configChanges="orientation">" 
    </activity> 

    <activity 
     android:name="com.metaio.junaio.plugin.view.ImageViewActivity" 
     android:theme="@style/Theme.Fullscreen" 
     android:configChanges="orientation"> 
    </activity> 

</application> 

</manifest> 

Antwort

0

Ich glaube, Sie versuchen, onClick Listener auf Schaltfläche anhängen, aber Sie tun dies auf falsche Weise, haben Sie implementiert OnTouch-Methode, die für Ihre gesamte Aktivität ist und in onTouch() MotionEvent.ACTION_DOWN: und einige andere Aktion Sie einige durchführen Ereignisse, die von onClick Methode aufrufen sollte ...

Sie sollten View.onClickListener auf Ihrer Aktivität implementieren und implementieren,

onClick(View v){ 
    switch(v.getId() 
    { 
    case R.id.btnFoo: 
    // perform your action 
    break; 

    } 

} 

und für Zuhörer auf Ihre Knopfbefestigungs sollten Sie Button.setOnClickListener(this);

+0

Vielen Dank, wird es jetzt überprüfen – user1285471

0

Versuchen Sie, diese (die Aufmerksamkeit auf ACTION_CANCEL zahlen, da diese aufgerufen wird, wenn Scroll blättert auf einem klickten Taste):

@Override 
public boolean onTouchEvent(MotionEvent event) { 
    if(isTouchable) { 
     int maskedAction = event.getActionMasked();   
     if (maskedAction == MotionEvent.ACTION_DOWN) { 
      this.setTextColor(resources.getColor(R.color.octane_orange)); 
      initialClick = event.getX(); 
     } else if (maskedAction == MotionEvent.ACTION_UP) { 
      this.setTextColor(defaultTextColor); 
      endingClick = event.getX(); 
      checkIfSwipeOrClick(initialClick, endingClick, range); 
     } else if(maskedAction == MotionEvent.ACTION_CANCEL) 
      this.setTextColor(defaultTextColor); 
    } 
    return true; 
}