我正在開發Android應用程序,但我仍然很新。我想要一個按鈕,當你按下這個按鈕時,會出現幾個TextViews和Buttons。所以我有一個主要的線性佈局,然後嵌入另一個線性佈局,裏面包含我想隱藏的東西。我有嵌套的線性佈局設置爲android:visibility =「gone」。嵌套線性佈局僅顯示在Android中設置爲可見後的第一個視圖
我遇到的問題是,它只顯示隱藏的線性佈局內的第一項而不是全部。我試圖讓它出現的方式是
vgAddView = (ViewGroup)findViewById(R.id.add_details);
btnAche.setOnClickListener(new OnClickListener(){
public void onClick(View v){
vgAddView.setVisibility(0);
}
});
我的XML文件是這樣的
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:text="@string/but_stomach_ache"
android:id="@+id/but_stomach_ache"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>
<Button
android:text="@string/but_food"
android:id="@+id/but_food"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/add_details"
android:visibility="gone">
<TextView
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/when_happen">
</TextView>
<Button
android:text="@string/happen_now"
android:id="@+id/happen_now"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
</LinearLayout>