당신이 코드를 통해 레이아웃을 생성하기 때문에 많은 들으, 당신은 XML 뷰에 표시되지 않습니다. 앱을 만들고 실행하면 Button
이 표시되어야합니다. 당신이 오히려 XML 뷰에서 Button
를 참조 할 경우
, 당신은 다음과 같이 할 수 main_layout.xml을 수정해야합니다 :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I am a Button"/>
</LinearLayout>
당신은 사용하여 자바 코드에서이 Button
에 대한 참조를 얻을 수 있습니다 후 코드 다음 호출 된 setContentView() :
Button button = (Button) findViewById(R.id.button);
당신은 장치 또는 에뮬레이터에서 프로젝트를 실행 했습니까? AFAIK 디자인 뷰는 XML 기반 레이아웃 용입니다. –