그래서 버튼에 대해서만 XML 레이아웃을 만들었습니다.id가없는 XML 파일로 동적 단추 레이아웃을 설정 하시겠습니까?
buttons.xml
<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="@drawable/b1" >
</Button>
main.java
public void addButton() {
Button btn=new Button(this);
}
어떻게 ID를 사용하지 않고 btn을하는 buttons.xml 레이아웃을 설정하는
?
인플레이터를 사용하십시오. – njzk2
을 사용했을 때 Button btn = (Button) LayoutInflater.from (this) .inflate (R.layout.buttons, null); 그래서 xml 파일에서 수학 높이와 폭을 계산합니다! –