目前,我正在使用this之类的渐变来处理自定义SeekBar。我试图用自己的风格实现搜索栏。所以我确实喜欢这样:
...
<style name="GreenSeekBar.Static.NoThumb">
<item name="android:progressDrawable">@drawable/sq_seekbar_clipped</item>
<item name="android:thumb">@null</item>
</style>`
这里的 sq_seekbar_clipped.xml:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="2dp"/>
<gradient
android:endColor="#00c492"
android:startColor="#e8e8e8" />
</shape>
</clip>
</item>
<item android:id="@android:id/secondaryProgress">
<shape android:shape="rectangle">
<size android:height="3dp" />
<solid android:color="@color/transparent" />
</shape>
</item>
</layer-list>
所以,除了一件事之外,一切都很有效 - 我收到了 this :
所以,正如你从我所得到的那样 - 渐变被裁剪。我需要渐变从0到[progress_value]。这可能吗?
有没有办法在第一(顶部链接)图片上绘制渐变?
答案 0 :(得分:4)
您只需要更改
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// 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);
}
@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) {
mMap.setMyLocationEnabled(true);
}
// Add a marker in Sydney and move the camera
//mMap.addMarker(new MarkerOptions().position(new LatLng(0,0)).title("Lets try this").snippet("gotcha"));
//LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
//Location myLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
//mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
//double user_latitude = myLocation.getLatitude();
//double user_longitude = myLocation.getLongitude();
//LatLng user_coord = new LatLng(user_latitude, user_longitude);
//mMap.animateCamera(CameraUpdateFactory.zoomTo(14));
//mMap.addMarker(new MarkerOptions().position(new LatLng(user_latitude,user_longitude)).title("You are here"));
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
Location location = locationManager.getLastKnownLocation(provider);
if (location != null) {
LatLng target = new LatLng(location.getLatitude(), location.getLongitude());
CameraPosition position = this.mMap.getCameraPosition();
CameraPosition.Builder builder = new CameraPosition.Builder();
builder.zoom(15);
builder.target(target);
this.mMap.animateCamera(CameraUpdateFactory.newCameraPosition(builder.build()));
//Marker our_marker = mMap.addMarker(new MarkerOptions().position(new LatLng(location.getLatitude(), location.getLongitude())).title("Local Bathroom").snippet("Tap for Rating").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
Intent intent = new Intent(MapsActivity.this, DummyContent.class);
startActivity(intent);
} });
}
//LatLng New_york = new LatLng(40, -73);
LatLng netherlands = new LatLng(40.715613, -73.604853);
LatLng studentcenter1 = new LatLng(40.715946, -73.602037);
LatLng studentcenter2 = new LatLng(40.716231, -73.601007);
LatLng bits = new LatLng(40.713889, -73.601651);
LatLng playhouse = new LatLng(40.713043, -73.600707);
LatLng calkins = new LatLng(40.713303, -73.599977);
LatLng axinn = new LatLng(40.714824, -73.600492);
LatLng library = new LatLng(40.714609, -73.601116);
LatLng alliance = new LatLng(40.716502, -73.602183);
//mMap.addMarker(new MarkerOptions().position(New_york).title("Welcome to the city!!"));
Marker alliance_marker = mMap.addMarker(new MarkerOptions().position(alliance).title("Alliance Hall's Bathroom").snippet("Tap for Rating").icon(BitmapDescriptorFactory.fromResource(R.drawable.finaltoilet)));
Marker library_marker = mMap.addMarker(new MarkerOptions().position(library).title("Axinn Library's Bathroom").snippet("Tap for Rating").icon(BitmapDescriptorFactory.fromResource(R.drawable.finaltoilet)));
Marker Hammer_marker = mMap.addMarker(new MarkerOptions().position(axinn).title("Hammer Lab's Bathroom").snippet("Tap for Rating").icon(BitmapDescriptorFactory.fromResource(R.drawable.finaltoilet)));
Marker calkins_marker = mMap.addMarker(new MarkerOptions().position(calkins).title("Calkins Hall's Bathroom").snippet("Tap for Rating").icon(BitmapDescriptorFactory.fromResource(R.drawable.finaltoilet)));
Marker playhouse_marker = mMap.addMarker(new MarkerOptions().position(playhouse).title("Playhouse's Bathroom").snippet("Tap for Rating").icon(BitmapDescriptorFactory.fromResource(R.drawable.finaltoilet)));
Marker bits_marker = mMap.addMarker(new MarkerOptions().position(bits).title("Bits and Bite's Bathroom").snippet("Tap for Rating").icon(BitmapDescriptorFactory.fromResource(R.drawable.finaltoilet)));
Marker studentcenter2_marker = mMap.addMarker(new MarkerOptions().position(studentcenter2).title("Game Room's Bathroom").snippet("Tap for Rating").icon(BitmapDescriptorFactory.fromResource(R.drawable.finaltoilet)));
Marker studentcenter1_marker = mMap.addMarker(new MarkerOptions().position(studentcenter1).title("Student Center's Bathroom").snippet("Tap for Rating").icon(BitmapDescriptorFactory.fromResource(R.drawable.finaltoilet)));
Marker netherlands_marker = mMap.addMarker(new MarkerOptions().position(netherlands).title("Netherland's Bathroom").snippet("Tap for Rating").icon(BitmapDescriptorFactory.fromResource(R.drawable.finaltoilet)));
Marker our_marker = mMap.addMarker(new MarkerOptions().position(new LatLng(location.getLatitude(), location.getLongitude())).title("Local Bathroom").snippet("Tap for Rating").icon(BitmapDescriptorFactory.fromResource(R.drawable.finaltoilet)));
mMap.setOnMarkerClickListener((GoogleMap.OnMarkerClickListener) this);
//mMap.moveCamera(CameraUpdateFactory.newLatLng(New_york));
}
mMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
public void onInfoWindowClick(Marker marker) {
Intent intent = new Intent(MapsActivity.this, PageActivity.class);
startActivity(intent);
}
});
到
<clip>
这是 sq_seekbar_clipped.xml :
<scale android:scaleWidth="100%">
答案 1 :(得分:0)
您应该在辅助进度和正在进行的纯色中设置渐变。
这样的事情:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/progress">
<clip>
<shape>
<size android:height="3dp" />
<solid android:color="@color/transparent" />
</shape>
</clip>
</item>
<item android:id="@android:id/secondaryProgress">
<shape android:shape="rectangle">
<corners android:radius="2dp"/>
<gradient
android:endColor="#00c492"
android:centerColor=""
android:startColor="#e8e8e8" />
</shape>
</item>
</layer-list>
另外,提供一些中心色以获得清晰的视野。