저는 안드로이드를 처음 접했고 ScrollView를 만들고 그 안에 TextViews와 pickers가 들어있는 세로 선형 레이아웃을 추가했습니다. 이 모든 것은 프로그래밍 방식으로 생성되었습니다. 내 문제는 setContentView (스크롤) 줄에 있습니다. 그것은 ConstraintLayout의 뒤쪽에 내가 만든 (프로그래밍 방식이 아닌) 모든 객체를 포함하는 것으로 보입니다. 그러나 저는 이미 동적 ScrollView의 높이를 800으로 설정했습니다. ScrollView 뒤쪽에 4 개의 버튼을 표시하려면 어떻게해야합니까?안드로이드 setContentview (scroll)은 ConstraintLayout 객체를 뒤에 숨 깁니다.
참조 스크린 샷 :
non dynamic objects in constraintlayout
programmatically created objects in linearlayout inside scrollview
여기에 코드입니다.
ScrollView scroll = new ScrollView(this);
scroll.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
800));
scroll.setFillViewport(true);
setContentView(scroll); //here is the line with issue
LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.VERTICAL);
LayoutParams lp1 = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
linearLayout.setLayoutParams(lp1);
scroll.addView(linearLayout);
for(int i = 0; i < res2.getCount(); i++)
{
NumberPicker numberPicker = new NumberPicker(this);
numberPicker.setMinValue(0);
numberPicker.setMaxValue(100);
TextView textView = new TextView(this);
textView.setText(/*textArray[i] + " " +*/ res2.getString(1));
linearLayout.addView(textView);
linearLayout.addView(numberPicker);
res2.moveToNext();
}
감사합니다. 프로그래밍 방식으로 생성하는 대신 XML에서 ScrollView (LinearLayout의 부모)도 선언해야합니까? –
정말 고마워요. 그것은 일했다 :). 그래서 이것이 최선의 방법입니다. 더 많은 제어를 위해 xml로 레이아웃을 생성 한 다음 동적으로 내용을 추가하십시오. –
예, 표시해야 할 내용을 처음부터 모르는 경우에만 프로그래밍 방식으로보기를 만들어야합니다. 그것이 당신을 도울 경우 정답으로 표시하십시오! :) –