在kivy语言中,每次滑块将其值更改import android.location.Geocoder;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.support.v7.widget.SearchView;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import java.io.IOException;
import java.util.List;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
private SearchView searchView;
private SupportMapFragment mapFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
searchView = findViewById(R.id.location);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
String location = searchView.getQuery().toString();
List<Address> addressList = null;
if (location != null || location != "") {
Geocoder geocoder = new Geocoder(MapsActivity.this);
try {
addressList = geocoder.getFromLocationName(location, 1);
} catch (IOException e) {
e.printStackTrace();
}
Address address = addressList.get(0);
LatLng latLng = new LatLng(address.getLatitude(),address.getLongitude());
mMap.addMarker(new MarkerOptions().position(latLng).title(location));
mMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
}
return false;
}
@Override
public boolean onQueryTextChange(String query) {
return false;
}
});
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
}
}```
"I expect that the app would not crash when I again hit enter to submit search in SearchView."
时,我都希望更改画布的角度值。
我试图通过使用“组”为PushMatrix中的“旋转操作”赋予ID
on_touch_move
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang.builder import Builder
kv = '''
<Seesaw>:
orientation: "horizontal"
Widget:
id: canvas_widget
size_hint_x: 0.85
canvas.before:
PushMatrix
Rotate:
group: 'a'
#angle: 0
axis: 0, 0, 1
origin: 300, 300
canvas:
Color:
rgb: (0, 0, 1)
Rectangle:
pos: 100,300
size: 400,20
canvas.after:
PopMatrix
Slider:
size_hint_x: 0.15
id: slider1
min: -60
max: 60
orientation: 'vertical'
on_touch_move: canvas_widget.a.angle = 45, root.printer()
'''
Builder.load_string(kv)
class Seesaw(BoxLayout):
def printer(self):
print('Slider value changed to: ', self.ids.slider1.value)
class SimpleApp(App):
def build(self):
seesaw = Seesaw()
return seesaw
if __name__ == '__main__':
SimpleApp().run()
I can't access the angle of the
一个ID,以及如何访问Rotation操作?PushMatrix
by using on_touch_move
of the Slider
in kv-language.
提前感谢您的时间。
答案 0 :(得分:0)
angle
添加新属性Widget:
angle: self.angle
canvas_widget.a.angle = 45
替换为canvas_widget.angle = 45
<Seesaw>:
orientation: "horizontal"
Widget:
id: canvas_widget
angle: 0 # new attribute
size_hint_x: 0.85
canvas.before:
PushMatrix
Rotate:
angle: self.angle # Assignment
axis: 0, 0, 1
origin: 300, 300
...
Slider:
...
on_touch_move:
root.printer()
canvas_widget.angle = 45