質問内容
activity_main.xml内の下にある二つ目のImageViewについて質問があります。
android:layout_marginTop="dp"
android:layout_marginLeft="dp"
のそれぞれの“dp”の前にMainActivity.javaの中にある
double k=a * i / e;
double l=d * j / f;
のkとlの数値を入れたいのですが、どのようにすればいいのかわかりません。
どのようにコードを打ち込めばよいのか教えていただけないでしょうか。
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout 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" tools:context=".MainActivity"> <FrameLayout android:layout_width="fill_parent" android:layout_height="wrap_content" > <ImageView android:layout_width="360dp" android:layout_height="225dp" android:src="@drawable/tizu2" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <ImageView android:layout_width="15dp" android:layout_height="15dp" android:src="@drawable/azaz" android:layout_marginTop="dp" android:layout_marginLeft="dp" /> </FrameLayout> </android.support.constraint.ConstraintLayout>
java
1public class MainActivity extends AppCompatActivity implements LocationListener{ 2 3 private Location location1; 4 5 double Lati = location1.getLatitude(); 6 double Longi = location1.getLongitude(); 7 8 double a=360; 9 double b=33.098; 10 double c=131.2063; 11 double d=225; 12 double e=0.0217; 13 double f=0.041; 14 double g=location1.getLatitude(); 15 double h=location1.getLongitude(); 16 double i=b - g; 17 double j=h - c; 18 double k=a * i / e; 19 double l=d * j / f; 20 21 22 LocationManager locationManager; 23 24 @Override 25 protected void onCreate(Bundle savedInstanceState) { 26 super.onCreate(savedInstanceState); 27 setContentView(R.layout.activity_main); 28 29 if (ContextCompat.checkSelfPermission(this, 30 Manifest.permission.ACCESS_FINE_LOCATION) != 31 PackageManager.PERMISSION_GRANTED) { 32 ActivityCompat.requestPermissions(this, 33 new String[]{Manifest.permission.ACCESS_FINE_LOCATION,}, 34 1000); 35 } else { 36 locationStart(); 37 38 locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 39 1000, 50, this); 40 41 } 42 } 43 44 private void locationStart() { 45 Log.d("debug", "locationStart()"); 46 47 // LocationManager インスタンス生成 48 locationManager = 49 (LocationManager) getSystemService(LOCATION_SERVICE); 50 51 if (locationManager != null && locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { 52 Log.d("debug", "location manager Enabled"); 53 } else { 54 // GPSを設定するように促す 55 Intent settingsIntent = 56 new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); 57 startActivity(settingsIntent); 58 Log.d("debug", "not gpsEnable, startActivity"); 59 } 60 61 if (ContextCompat.checkSelfPermission(this, 62 Manifest.permission.ACCESS_FINE_LOCATION) != 63 PackageManager.PERMISSION_GRANTED) { 64 ActivityCompat.requestPermissions(this, 65 new String[]{Manifest.permission.ACCESS_FINE_LOCATION,}, 1000); 66 67 Log.d("debug", "checkSelfPermission false"); 68 return; 69 } 70 71 locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 72 1000, 50, this); 73 74 } 75 76 // 結果の受け取り 77 78 /** 79 * Android Quickstart: 80 * https://developers.google.com/sheets/api/quickstart/android 81 * <p> 82 * Respond to requests for permissions at runtime for API 23 and above. 83 * 84 * @param requestCode The request code passed in 85 * requestPermissions(android.app.Activity, String, int, String[]) 86 * @param permissions The requested permissions. Never null. 87 * @param grantResults The grant results for the corresponding permissions 88 * which is either PERMISSION_GRANTED or PERMISSION_DENIED. Never null. 89 */ 90 @Override 91 public void onRequestPermissionsResult( 92 int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 93 if (requestCode == 1000) { 94 // 使用が許可された 95 if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { 96 Log.d("debug", "checkSelfPermission true"); 97 98 locationStart(); 99 100 } else { 101 // それでも拒否された時の対応 102 Toast toast = Toast.makeText(this, 103 "これ以上なにもできません", Toast.LENGTH_SHORT); 104 toast.show(); 105 } 106 } 107 } 108 109 @Override 110 public void onStatusChanged(String provider, int status, Bundle extras) { 111 switch (status) { 112 case LocationProvider.AVAILABLE: 113 Log.d("debug", "LocationProvider.AVAILABLE"); 114 break; 115 case LocationProvider.OUT_OF_SERVICE: 116 Log.d("debug", "LocationProvider.OUT_OF_SERVICE"); 117 break; 118 case LocationProvider.TEMPORARILY_UNAVAILABLE: 119 Log.d("debug", "LocationProvider.TEMPORARILY_UNAVAILABLE"); 120 break; 121 } 122 } 123 124 @Override 125 public void onLocationChanged(Location location) { 126 127 location1 = location; 128 129 } 130 131 @Override 132 public void onProviderEnabled(String provider) { 133 134 } 135 136 @Override 137 public void onProviderDisabled(String provider) { 138 139 } 140}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/01/27 01:48