1
버튼을 만들고 addView()
을 사용하여 onClickListener()
에 차트를 그려야합니다. 하지만 그것은 자동으로보기의 높이를 확장하지 않을 경우 바운드 차트가 있습니다. 그래서 모든 차트가 그려 졌을 때보기의 높이를 추가하고 싶습니다. getLayoutParams().height
을 사용하여 높이를 수정하려고 시도했지만 작동하지 않습니다.Android :보기 높이를 설정하는 방법?
public class MainActivity extends Activity {
private TableLayout layout;
private Button btnDraw;
public void onCreate(Bundle savedInstanceState){
layout=findViewById((TableLayout) findViewById(R.id.tableLayout));
btnDraw=findViewById((Button) findViewById(R.id.btnDraw));
btnDraw.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
layout.addView(new Chart(MainActivity.this)
}
});
}
class Chart extends View {
public void onDraw(Canvas c) {
int addHeight=0;
for(...){ //draw several chart
...
addHeight+=500;
}
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) layout.getLayoutParams();
params.height += addHeight;
layout.setLayoutParams(params);
}
}
}
여기에서 나는 또한 루프 외부 onMeasure(getWidth(),addHeight)
전화를 시도하지만 여전히 작동하지 XML 코드
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<TableLayout
android:id="@+id/tableLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TableRow>
<Button
android:id="@+id/btnDraw"
android:layout_span="2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Draw" />
</TableRow>
...
</TableLayout>
</ScrollView>
입니다. 당신이 그것에게 팔 방법을 수행하려는 경우
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
setMeasuredDimension(widthMeasureSpec, widthMeasureSpec);
}