내 Android 애플리케이션의 지정된 영역에 LinearLayout
있는 LinearLayout
또한 동적으로 표시 할 수있는 메서드를 만들고 싶습니다. 이 선형 레이아웃의 수는 주어진 수에 따라 변경됩니다.
또한 각각에 LinearLayout
a를 표시하고 Button
그 아래에 TextView
.
이미 만든 방법은 다음과 같습니다.
public void putLinearLayout(double number){
int mButtonHeight = 100;
int mButtonWidth = 80;
LinearLayout Linear = (LinearLayout)findViewById(R.id.linearlayout1);
for(int i=1;i<=number;i++)
{
LinearLayout L = new LinearLayout(this);
Button b= new Button(this);
TextView tv = new TextView(this);
L.setOrientation(LinearLayout.HORIZONTAL);
b.setWidth(mButtonWidth);
b.setHeight(mButtonHeight);
L.addView(b);
L.addView(tv);
Linear.addView(L);
}
}
layoutparams 만 설정하면됩니다.
public void putLinearLayout(double number){
LinearLayout Linear = (LinearLayout)findViewById(R.id.linearlayout1);
int mButtonHeight = 100;
int mButtonWidth = 80;
for(int i=1;i<=number;i++)
{
LinearLayout L = new LinearLayout(this);
L.setBackgroundColor(Color.WHITE);
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); //<--this line , is what you were missing
L.setLayoutParams(params); //<-- and then this
Button b= new Button(this);
b.setText(i+"");
TextView tv = new TextView(this);
tv.setText("i am textview number: "+i);
L.setOrientation(LinearLayout.HORIZONTAL);
b.setWidth(mButtonWidth);
b.setHeight(mButtonHeight);
L.addView(b);
L.addView(tv);
Linear .addView(L);
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다