2
프로그래밍 방식으로 레이아웃 및 XML을 생성해야하는 경우가 필요합니다. 어떤 접근 방식을 취해야합니까? 저에게 알려주세요. 고맙습니다.Android : xml 병합 및 프로그래밍 방식으로 레이아웃 생성
생성 레이아웃 :
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
LinearLayout audio = new LinearLayout(this);
audio.setGravity(Gravity.BOTTOM | Gravity.CENTER);
RecordButton = new RecordButton(this);
audio.addView(RecordButton,
new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
Gravity.CENTER | Gravity.BOTTOM));
PlayButton = new PlayButton(this);
audio.addView(PlayButton,
new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
Gravity.CENTER | Gravity.BOTTOM));
setContentView(audio);
}
XML :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:gravity="top">
<Button
android:id="@+id/next"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="130dp"
android:background="#54C571"
android:text="Next"
android:textColor="#FFFFFF"
android:textSize="23sp"
android:textStyle="bold" />
'some_view_in_xml.addView (generated_layout); –
@KNeerajLal 선형 레이아웃은 어떻습니까? 어떻게 그들을 포함시켜야합니까? 이건'audio.xml.addView (generated)'와 같은가요? 나는 노력했고 XML은 해결할 수 없다고 말했다. –
XML 레이아웃을 보여준다. –