Android NumberPicker字符串值不适合
a制作了一个customNumberPicker:Android NumberPicker字符串值不适合,android,textview,numberpicker,Android,Textview,Numberpicker,a制作了一个customNumberPicker: public class CustomNumberPicker extends NumberPicker { public CustomNumberPicker(Context context, AttributeSet attrs) { super(context, attrs); } @Override public void addView(View child) { s
public class CustomNumberPicker extends NumberPicker {
public CustomNumberPicker(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void addView(View child) {
super.addView(child);
updateView(child);
}
@Override
public void addView(View child, int index, android.view.ViewGroup.LayoutParams params) {
super.addView(child, index, params);
updateView(child);
}
@Override
public void addView(View child, android.view.ViewGroup.LayoutParams params) {
super.addView(child, params);
updateView(child);
}
private void updateView(View view) {
if (view instanceof TextView) {
TextView tv = (TextView) view;
tv.setLines(3);
tv.setTextSize(16);
tv.setTextColor(Color.BLUE);
tv.setPadding(20, 10, 20, 10);
tv.setMaxWidth(10);
tv.setSingleLine(false);
tv.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
tv.requestLayout();
tv.invalidate();
}
}
}
}
我这样称呼它:
xml:
但是长文本不适合屏幕
我想让它像多行一样工作。
请帮我做这个。
谢谢大家!
以下是一段视频:
预期的结果是什么?您是否希望他们将内容包装成几行,或者在每个项目的末尾或中间放置“…”?是的,我希望它像多行一样工作。如果您将
updateView
方法的最后一行替换为tv.setLayoutParams(新的LinearLayout.LayoutParams(LayoutParams.MATCH\u PARENT,LayoutParams.wrap\u content)),会怎么样代码>?我还会尝试在这里更改方法调用的顺序super.addView(child);更新视图(儿童)代码>@foxanna没有任何变化。但有些情况下,如果我点击一个项目,它会将文本包装成多行,但一旦更改,它就会还原多行
<hu.enyim.pickerexample.CustomNumberPicker
android:id="@+id/picker"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"/>
picker = (CustomNumberPicker) findViewById(R.id.picker);
picker.setMinValue(0);
picker.setMaxValue(values.length - 1);
picker.setDisplayedValues(values);