Tag: android spinner

创建一个微调器,当选择一个项目时调整它的宽度

我有一个微调,我想它的宽度是用户选择的项目的宽度。 当试图获得在两个不同的设备上的文字宽度,我得到两个不同的结果。 要获得文本宽度,我正在做以下事情: fun textDim(text: String): Int { val bounds = Rect() val textPaint = Paint() textPaint.textSize = 16f textPaint.getTextBounds(text, 0, text.length, bounds) return bounds.width() } 但是,这不起作用,并且不能在两台设备上正确缩放。 所以,我试了一下 fun textDim(text: String, context: Context): Int { val bounds = Rect() val textPaint = Paint() textPaint.textSize = 16f textPaint.getTextBounds(text, 0, text.length, bounds) return bounds.width() * context.resources.displayMetrics.density.toInt() } […]

DataBinding错误在android微调

我正在尝试设置双向绑定与Android的微调,但我得到以下错误。 引起:android.databinding.tool.util.LoggedErrorException:发现数据绑定错误。 **** /数据绑定错误****味精:无法找到属性“绑定:selectedValue”的值类型java.lang.String android.widget.Spinner **** \数据绑定错误的getter * 这是我的SpinnerBindingUtils public class SpinnerBindingUtils { @BindingAdapter(value = {"bind:selectedValue", "bind:selectedValueAttrChanged"}, requireAll = false) public static void bindSpinnerData(AppCompatSpinner pAppCompatSpinner, String newSelectedValue, final InverseBindingListener newTextAttrChanged) { pAppCompatSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { newTextAttrChanged.onChange(); } @Override public void onNothingSelected(AdapterView<?> parent) { } […]