我正在开发一个 Android 应用程序,但我还是很新。我想要一个按钮,当你按下那个按钮时,会出现一些 TextViews 和 Buttons。所以我有一个主要的线性布局,然后是另一个嵌套在里面的线性布局,其中包含我想要隐藏的东西。我将嵌套线性布局设置为 android:visibility="gone"。
我遇到的问题是它只显示隐藏线性布局中的第一个项目,而不是所有项目。我试图让它出现的方式是
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>