问题
I'd like to display this under a toggle button when the toggle button is pressed then disappear when the toggle button is pressed again, I've looked into expandable list views but it's seems over complicated for a few items that wont change visually.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:textSize="40dp"
android:id="@+id/button"
android:text="Dummy Job"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<!-- <android.support.v7.widget.RecyclerView
android:id="@+id/jobStats"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView> -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="40dp"
android:text="New Text"
android:id="@+id/viewMachine" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="40dp"
android:text="New Text"
android:id="@+id/viewItem" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="40dp"
android:text="New Text"
android:id="@+id/viewDate" />
<LinearLayout
android:id="@+id/testing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40dp"
android:text="Button"
android:id="@+id/bJobOpen"
android:layout_weight="1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40dp"
android:text="Button"
android:id="@+id/bJobEdit"
android:layout_weight="1" />
<Button
android:layout_width="245dp"
android:layout_height="wrap_content"
android:text="Button"
android:id="@+id/bJobExport"
android:textSize="40dp"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
Here is what i have for it's creation.
LinearLayout layout = (LinearLayout) findViewById(R.id.ReportsLayout);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f);
//layout.setLayoutParams(lp);
//layout.setLayoutParams(lp);
//layout.setOrientation(LinearLayout.HORIZONTAL);
TextView viewMachine = new TextView(Reports.this);
TextView viewItem = new TextView(Reports.this);
TextView viewDate = new TextView(Reports.this);
LinearLayout horLayout = new LinearLayout(context);
Button enterJob = new Button(Reports.this);
Button editJob = new Button(Reports.this);
Button exportJob = new Button(Reports.this);
//enterJob.setLayoutParams(lp);
//editJob.setLayoutParams(lp);
//exportJob.setLayoutParams(lp);
if( button.isChecked()==(true)) {
layout.addView(viewMachine,lp);
layout.addView(viewItem,lp);
layout.addView(viewDate,lp);
layout.addView(enterJob,lp);
layout.addView(editJob, lp);
layout.addView(exportJob, lp);
}
else{
//layout.setVisibility(View.INVISIBLE);
}
}
};
}
Problems are when i create this it looks like this
setting the view to invis
回答1:
suggestion to use this lib directly in your app.
ExpandableLayout
来源:https://stackoverflow.com/questions/35101639/without-using-inflater-and-recyclerview-whats-the-best-way-to-recreate-my-xml-i