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(生成)'?我試過了,它說xml無法解析 –
顯示你的xml佈局。 –