fix: unify widget logo height to 12dp for all services, prevent layout shift on switch

This commit is contained in:
WaterRain 2026-07-06 22:41:57 +00:00
parent 7ad1934474
commit 7cdb3d9b3c
No known key found for this signature in database

View File

@ -91,14 +91,9 @@ class OpenCodeGoWidgetProvider : AppWidgetProvider() {
views.setTextViewText(R.id.widget_switch, shortName(selectedService)) views.setTextViewText(R.id.widget_switch, shortName(selectedService))
views.setTextViewText(R.id.widget_service_title, "${selectedService.displayName} · 额度") views.setTextViewText(R.id.widget_service_title, "${selectedService.displayName} · 额度")
views.setImageViewResource(R.id.widget_logo, widgetLogo(selectedService)) views.setImageViewResource(R.id.widget_logo, widgetLogo(selectedService))
// Ollama logo 是正方形,需要动态调整 ImageView 尺寸 // 所有服务 logo 统一 12dp 高,wrap_content 宽度自适应比例
if (selectedService == ServiceType.OLLAMA) { views.setViewLayoutWidth(R.id.widget_logo, -2f, TypedValue.COMPLEX_UNIT_DIP) // wrap_content
views.setViewLayoutWidth(R.id.widget_logo, 20f, TypedValue.COMPLEX_UNIT_DIP) views.setViewLayoutHeight(R.id.widget_logo, 12f, TypedValue.COMPLEX_UNIT_DIP)
views.setViewLayoutHeight(R.id.widget_logo, 20f, TypedValue.COMPLEX_UNIT_DIP)
} else {
views.setViewLayoutWidth(R.id.widget_logo, 22f, TypedValue.COMPLEX_UNIT_DIP)
views.setViewLayoutHeight(R.id.widget_logo, 12f, TypedValue.COMPLEX_UNIT_DIP)
}
val cached = cache.get(selectedService) val cached = cache.get(selectedService)
if (cached != null) { if (cached != null) {
selectedHasCachedData = true selectedHasCachedData = true