문제

So because of the limited support library for the number picker (And because it's WAAY too big), I'm making my own number picker. Unfourtunately, it's not appearing correctly.

Any help on fixing it would be great.

Up arrow and down arrows occupy the same space (overlapping each other so that only the down arrow appears). The down arrow should be UNDER the text representing the number. Any idea why this is?

Here's the screenshot: number picker is wrong

And here's the code for it:

    //"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);
도움이 되었습니까?

해결책

//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);

This might cause your downArrow to actually exist but its ImageView is missing its image.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top