因为数字选择器的支持库有限(而且因为WAAY太大了),我正在制作自己的号码选择器。不幸的是,它没有正确显示。
任何有关修复它的帮助都会很棒。
向上箭头和向下箭头占据相同的空间(相互重叠,只显示向下箭头)。向下箭头应位于表示数字的文本下方。 知道为什么会这样吗?
这是截图:
以下是代码:
//"Number-Picker"
LinearLayout numPicker = new LinearLayout(context);
numPicker.setOrientation(LinearLayout.VERTICAL);
numPicker.setLayoutParams(pickerItemParams);
LinearLayout.LayoutParams upDownParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f);
//Up button
LinearLayout upSpace = new LinearLayout(context);
ImageView upArrow = new ImageView(context);
upArrow.setBackgroundResource(R.drawable.arrow_up);
upSpace.setLayoutParams(upDownParams);
upSpace.addView(upArrow);
//text
LinearLayout numSpace = new LinearLayout(context);
TextView pickerNum = new TextView(context);
pickerNum.setText(String.valueOf(textValue));
numSpace.setLayoutParams(upDownParams);
numSpace.addView(pickerNum);
//down
LinearLayout downSpace = new LinearLayout(context);
ImageView downArrow = new ImageView(context);
upArrow.setBackgroundResource(R.drawable.arrow_down);
downSpace.setLayoutParams(upDownParams);
downSpace.addView(downArrow);
numPicker.addView(upSpace);
numPicker.addView(numSpace);
numPicker.addView(downSpace);
答案 0 :(得分:3)
//down
LinearLayout downSpace = new LinearLayout(context);
ImageView downArrow = new ImageView(context);
upArrow.setBackgroundResource(R.drawable.arrow_down); // <----- Should be downArrow
downSpace.setLayoutParams(upDownParams);
downSpace.addView(downArrow);
这可能会导致您的downArrow实际存在,但其ImageView缺少其图像。