This article shares the Android imitation Taobao product list switching for your reference. The specific content is as follows
Source code:Android realizes Taobao product list switching
Layout file
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:andro xmlns:tools="/tools" android: android:layout_width="match_parent" android:layout_height="match_parent" android:padding="3dp" tools:context=".a3_.MainActivity"> <Button android: android:text="Switch layout" android:textSize="20dp" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <ListView android: android:layout_width="match_parent" android:layout_height="match_parent"> </ListView> <GridView android: android:numColumns="2" android:visibility="gone" android:layout_width="match_parent" android:layout_height="match_parent"> </GridView> </FrameLayout>
Core code
package .a3_; import .; import ; import ; import ; import ; import ; import ; import ; public class MainActivity extends AppCompatActivity { private ListView lv; private GridView gv; private Button button; //Set default display or hideprivate boolean isLvShow = true; private boolean isGvShow = false; @Override protected void onCreate(Bundle savedInstanceState) { (savedInstanceState); setContentView(.activity_main); //Initialize the control lv = (ListView) findViewById(); gv = (GridView) findViewById(); button = (Button) findViewById(); //Set the adapter (new MyAdapter()); (new MyAdapter()); //Set click event for the button (new () { @Override public void onClick(View v) { if (isLvShow){ (); (); }else { (); (); } //Inverse the display or hide isLvShow = !isLvShow; isGvShow = !isGvShow; } }); } class MyAdapter extends BaseAdapter{ @Override public int getCount() { return 20; } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { // Set layout for listview if (convertView==null){ convertView = (getApplicationContext(),,null); } return convertView; } } }
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.