• TabHost


    逻辑

    package com.example.administrator.hello;
    
    import android.app.TabActivity;
    import android.content.Intent;
    import android.support.v4.view.LayoutInflaterCompat;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.LayoutInflater;
    import android.widget.ExpandableListView;
    import android.widget.TabHost;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    
    public class MainActivity extends TabActivity {
        private TabHost tabHost;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            tabHost=(TabHost)findViewById(R.id.tab);
            tabHost.addTab(tabHost.newTabSpec("TAB1").setIndicator("线性布局").setContent(R.id.lay1));
            tabHost.addTab(tabHost.newTabSpec("TAB2").setIndicator("绝对布局").setContent(R.id.lay2));
            tabHost.addTab(tabHost.newTabSpec("TAB3").setIndicator("相对布局").setContent(new Intent(MainActivity.this,A.class)));
    
        }
    }

    布局

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/lay3">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="hello 3"
            android:id="@+id/tv3"/>
    
    </RelativeLayout>
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/lay1">
        <TextView
            android:text="111111111"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    
    </LinearLayout>
    <?xml version="1.0" encoding="utf-8"?>
    <AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/lay2"
        >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="hello word 2"/>
    </AbsoluteLayout>
    <?xml version="1.0" encoding="utf-8"?>
    <TabHost android:id="@+id/tab"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        xmlns:android="http://schemas.android.com/apk/res/android">
    
        <LinearLayout
            android:id="@+id/lay1"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <TabWidget
                android:id="@+id/we"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
    
            </TabWidget>
    <FrameLayout
        android:id="@+id/fra"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
    
    </FrameLayout>
        </LinearLayout>
    
    </TabHost>
    package com.example.administrator.hello;
    
    import android.app.Activity;
    import android.os.Bundle;
    
    /**
     * Created by Administrator on 2018/5/21.
     */
    public class A extends Activity{
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.a);
        }
    }
    package com.example.administrator.hello;
    
    import android.content.Context;
    import android.view.LayoutInflater;
    import android.view.TextureView;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.BaseExpandableListAdapter;
    import android.widget.ExpandableListAdapter;
    import android.widget.TextView;
    
    import java.util.List;
    import java.util.Map;
    
    /**
     * Created by Administrator on 2018/5/21.
     */
    public class MyAdapter extends BaseExpandableListAdapter {
        private Context context;
        private List<String> listl;
        private Map<String,List<String>> map;
    
    
        MyAdapter( Context context, List<String> listl, Map<String,List<String>> map)
        {
            this.context=context;
            this.listl=listl;
            this.map=map;
    
        }
    
        @Override
        public int getGroupCount() {
            return listl.size();
        }
    
        @Override
        public int getChildrenCount(int groupPosition) {
            String key =listl.get(groupPosition);
            List list_c= map.get(key);
            return list_c.size();
        }
    
        @Override
        public Object getGroup(int groupPosition) {
    
            return listl.get(groupPosition);
        }
    
        @Override
        public Object getChild(int groupPosition, int childPosition) {
            String key =listl.get(groupPosition);
            List list_c= map.get(key);
            return list_c;
        }
    
        @Override
        public long getGroupId(int groupPosition) {
            return groupPosition;
        }
    
        @Override
        public long getChildId(int groupPosition, int childPosition) {
            return childPosition;
        }
    
        @Override
        public boolean hasStableIds() {
            return true;
        }
    
        @Override
        public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
            if(convertView==null)
            {
                 Viewh_p viewh_p=new Viewh_p();
                convertView= LayoutInflater.from(context).inflate(R.layout.tv_p,null);
                viewh_p.tv_p=(TextView)convertView.findViewById(R.id.tv_p);
                convertView.setTag(viewh_p);
    
            }
            else{
    
    
            }
            return null;
        }
    
        @Override
        public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
            return null;
        }
    
        @Override
        public boolean isChildSelectable(int groupPosition, int childPosition) {
            return true;
        }
    }
    
    
    class Viewh_p{
         TextView tv_p;
    }
    
    class Viewh_c{
         TextView tv_c;
    }
  • 相关阅读:
    UVA101 The Blocks Problem 题解
    洛谷P2790 ccj与zrz之积木问题 题解
    NOIp2018 TG day1 T2暨洛谷P5020 货币系统:题解
    网页学习:day1
    NOIP2018提高/普及成绩
    NOIP2018普及T4暨洛谷P5018 对称二叉树题解
    NOIP2018&2013提高组T1暨洛谷P5019 铺设道路
    比赛:小奔的方案 solution
    比赛:小奔的矩形solution
    比赛:小奔与不等四边形solution
  • 原文地址:https://www.cnblogs.com/excellencesy/p/9067237.html
Copyright © 2020-2023  润新知