2017-09-24 13 views
1

私がしたいことは、マップ上にボタンを表示することです。このアイデアは、ボタンに触れ、画像でもある他のボタンに表示することです。 何らかの理由で、イメージが表示されないように表示されます。これとは別に、アプリが初期化するときに3つのボタンが表示されます。Androidスタジオで画像ボタンが正しく表示されない理由をご存知ですか?

https://imgur.com/a/0iHZ0(悪い品質申し訳ありません)

コード

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, LocationListener { 

     private GoogleMap mMap; 
     LocationManager locationManager; 
     String provider; 
     LatLng myPosition; 

     TextView climaText; 
     ImageButton reportes; 
     ImageButton playas; 
     ImageButton res; 
     boolean reportesState = false; 



     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.activity_maps); 

      climaText = (TextView) findViewById(R.id.climaText); 

      locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
      provider = locationManager.getBestProvider(new Criteria(), false); 
      if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 
       return; 
      } 
      locationManager.requestLocationUpdates(provider, 400, 1, this); 
      Location locationActual = locationManager.getLastKnownLocation(provider); 
      Double lat = locationActual.getLatitude(); 
      Double lng = locationActual.getLongitude(); 
      downloadTask getData = new downloadTask(); 
      getData.execute("//http://samples.openweathermap.org/data/2.5/weather?lat="+String.valueOf(lat)+"&lon="+String.valueOf(lng)+"&appid=4ec901292084195e70a7a39b5259cf17"); 


      /* locationRequest = new LocationRequest(); 
      //locationRequest.setInterval(7500); 
      //locationRequest.setFastestInterval(5000); 
      locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);*/ 

      //Si no inicializo aca, debo ponerle final dentro del metodo a cada boton 
      reportes = (ImageButton) findViewById(R.id.reporte); 
      playas = (ImageButton) findViewById(R.id.reportePlayas); 
      res = (ImageButton) findViewById(R.id.reporteRes); 

      // Obtain the SupportMapFragment and get notified when the map is ready to be used. 
      SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
        .findFragmentById(R.id.map); 
      mapFragment.getMapAsync(this); 
     } 

    /** 
    * Manipulates the map once available. 
    * This callback is triggered when the map is ready to be used. 
    * This is where we can add markers or lines, add listeners or move the camera. In this case, 
    * we just add a marker near Sydney, Australia. 
    * If Google Play services is not installed on the device, the user will be prompted to install 
    * it inside the SupportMapFragment. This method will only be triggered once the user has 
    * installed Google Play services and returned to the app. 
    */ 
    @Override 
    public void onMapReady(GoogleMap googleMap) { 
     mMap = googleMap; 

     if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 
      return; 
     } 
     mMap.setMyLocationEnabled(true); 

     Location locationActual = locationManager.getLastKnownLocation(provider);; 
     if(locationActual != null) { 
      // Getting latitude of the current location 
      double latitude = locationActual.getLatitude(); 
      // Getting longitude of the current location 
      double longitude = locationActual.getLongitude(); 
      // Creating a LatLng object for the current location 
      myPosition = new LatLng(latitude, longitude); 
      mMap.moveCamera(CameraUpdateFactory.newLatLng(myPosition)); 
      mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(myPosition, 16)); 
      } 
     } 


    @Override 
    public void onLocationChanged(Location location) { 
     Log.i("TESTTAG", "onLocationChanged called"); 
     LatLng currentPosition = new LatLng(location.getLatitude(),location.getLongitude()); 
     mMap.moveCamera(CameraUpdateFactory.newLatLng(currentPosition)); 
     mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(currentPosition, 16)); 
    } 



    @Override 
    public void onStatusChanged(String s, int i, Bundle bundle) { 

    } 

    @Override 
    public void onProviderEnabled(String s) { 

    } 

    @Override 
    public void onProviderDisabled(String s) { 

    } 

    @Override 
    protected void onResume() { 
     super.onResume(); 

     if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 
      return; 
     } 
     locationManager.requestLocationUpdates(provider, 400, 1, this); 

    } 

    @Override 
    protected void onPause() { 
     super.onPause(); 
     locationManager.removeUpdates(this); 

    } 


    /* 
    public void obtenerClima(){ 

     CityAsyncTask task = new CityAsyncTask(); 
     task.execute("http://api.openweathermap.org/data/2.5/weather?q=London,uk"); 

    }*/ 

    public void startDialogReportePlayas(View view) { 
     AlertDialog.Builder mBuilder = new AlertDialog.Builder(MapsActivity.this); 
     View mView = getLayoutInflater().inflate(R.layout.dialog_playas,null); 
     mBuilder.setView(mView); 
     AlertDialog dialog = mBuilder.create(); 
     dialog.show(); 

    } 

    public void startDialogReporteRes(View view) { 
     AlertDialog.Builder mBuilder = new AlertDialog.Builder(MapsActivity.this); 
     View mView = getLayoutInflater().inflate(R.layout.dialog_restaurantes,null); 
     mBuilder.setView(mView); 
     AlertDialog dialog = mBuilder.create(); 
     dialog.show(); 

    } 


    public void buttonClickAppear(View view){ 
     if(!reportesState) { 
      playas.setVisibility(View.VISIBLE); 
      res.setVisibility(View.VISIBLE); 
      reportesState = true; 
     }else{ 
      playas.setVisibility(View.GONE); 
      res.setVisibility(View.GONE); 
      reportesState = false; 
     } 
    } 

} 
:私はそれらを表示したいので、これは私がそれらの1

に押した後にこれが今何が起こっているかで起こるべきではありませんあなたがすべき場合Inthis

レイアウト

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#ffffff" 
    android:padding="0dp" 
    android:paddingBottom="@dimen/fab_margin" 
    android:paddingLeft="@dimen/fab_margin" 
    android:paddingRight="@dimen/fab_margin" 
    android:paddingTop="@dimen/fab_margin"> 

    <fragment xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:map="http://schemas.android.com/apk/res-auto" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/map" 
     android:name="com.google.android.gms.maps.SupportMapFragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentEnd="true" 
     tools:context="com.naluapp.naluapp.MapsActivity" 
     android:layout_alignParentTop="true" 
     android:layout_alignEnd="@+id/reporte" /> 

    <TextView 
     android:id="@+id/climaText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginStart="150dp" 
     android:layout_marginTop="20dp" 
     android:elevation="0dp" 
     android:text="Hola mundo" /> 

    <ImageButton 
     android:id="@+id/reporte" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentEnd="true" 
     android:layout_marginBottom="5dp" 
     android:layout_marginEnd="5dp" 
     android:contentDescription="buttonAppear" 
     android:onClick="buttonClickAppear" 
     app:srcCompat="@drawable/mapslocicon64pxl" /> 

    <ImageButton 
     android:id="@+id/reporteRes" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/reportePlayas" 
     android:layout_alignStart="@+id/reportePlayas" 
     android:layout_marginBottom="10dp" 
     android:contentDescription="" 
     android:onClick="startDialogReporteRes" 
     app:srcCompat="@drawable/mapslocicon64pxl" /> 

    <ImageButton 
     android:id="@+id/reportePlayas" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/reporte" 
     android:layout_alignStart="@+id/reporte" 
     android:layout_marginBottom="10dp" 
     android:contentDescription="" 
     android:onClick="startDialogReportePlayas" 
     app:srcCompat="@drawable/mapslocicon64pxl" /> 


</RelativeLayout> 
+0

私のポストを参照してくださいあなたに役立ちます – Raja

答えて

0

ビューの呼び出しbringToFront()がsrCompatを変更することで発見された(前)

yourView.bringToFront(); 

reportes.bringToFront(); 

playas.bringToFront(); 

res.bringToFront(); 

が、それはあなたに

+0

答えをありがとう、私はこれを試してみましょう! –

+0

私はそれを私のマップクラスのonCreateメソッドに置くが、何も起こらない。私はそれ以外の何かをする必要がありますか? –

0

ソリューションを助けることを願っています。例えば、トップに入るとき BringToFront関数を使用する必要がありただsrcに。

関連する問題