Android_tablayout
2024-05-29 23:07:34
compile 'com.android.support:design:26.0.0-alpha1'
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" tools:context="com.example.lian.MainActivity"><android.support.design.widget.TabLayout android:layout_width="match_parent" android:layout_height="60dp" android:id="@+id/tabLayout" app:tabIndicatorColor="@color/colorAccent" android:background="#fff" app:tabMode="scrollable" app:tabSelectedTextColor="@color/colorPrimaryDark" app:tabTextColor="#000" app:tabIndicatorHeight="4dp"></android.support.design.widget.TabLayout><android.support.v4.view.ViewPager android:id="@+id/viewPager" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/tabLayout" /> </LinearLayout>
//隐藏不占位GONE
package com.example.lian; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; public class NewFragment extends Fragment {private View v;@Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {super.onCreateView(inflater, container, savedInstanceState);v = View.inflate(getActivity(), R.layout.listview, null);return v;}@Override public void onActivityCreated(@Nullable Bundle savedInstanceState) {super.onActivityCreated(savedInstanceState);//获取传递过来的参数 可以根据接收过来的信息做网络请求 String string = getArguments().getString("name", "柴晓凯");TextView shuju = v.findViewById(R.id.shuju);if(string.equals("h")){shuju.setText(string);shuju.setVisibility(View.GONE);}else{shuju.setText(string);shuju.setVisibility(View.VISIBLE);}} }
package com.example.lian; import android.os.Bundle; import android.support.design.widget.TabLayout; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import java.util.ArrayList;public class MainActivity extends FragmentActivity {private TabLayout tabLayout;private ViewPager viewPager;private ArrayList<String> titleList = new ArrayList<String>();private MPagerAdapter mPagerAdapter;@Override protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);tabLayout = (TabLayout) findViewById(R.id.tabLayout);viewPager = (ViewPager) findViewById(R.id.viewPager);titleList.add("张三");titleList.add("李四");//ctrl+p 提示参数的快捷键 mPagerAdapter = new MPagerAdapter(getSupportFragmentManager());viewPager.setAdapter(mPagerAdapter);//设置TabLayout的模式 tabLayout.setTabMode(TabLayout.MODE_FIXED);//让tablayout和Viewpager关联; tabLayout.setupWithViewPager(viewPager);}class MPagerAdapter extends FragmentPagerAdapter{public MPagerAdapter(FragmentManager fm) {super(fm);}@Override public Fragment getItem(int position) {NewFragment fragment = new NewFragment();Bundle bundle = new Bundle();if(titleList.get(position).equals("柴晓凯")){bundle.putString("name","h");}else if(titleList.get(position).equals("倩倩")){bundle.putString("name","倩倩");}fragment.setArguments(bundle);return fragment;}@Override public int getCount() {return titleList.size();}//需要重写个返回标题的方法; @Override public CharSequence getPageTitle(int position) {return titleList.get(position);}} }
<?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"><TextView android:id="@+id/shuju" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="数据"/><TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/shuju" android:text="kkkk"/> </RelativeLayout>
//显示VISIBLE
//INVISIBLE 占位
唐三 2018/01/16 19:09:44
显示隐藏布局/控件
可以写在点击事件中
layoutID.setVisibility(View.VISIBLE);//这一句显示布局LinearLayout区域
显示隐藏布局/控件
可以写在点击事件中
layoutID.setVisibility(View.VISIBLE);//这一句显示布局LinearLayout区域
layoutID.setVisibility(View.GONE);//这一句即隐藏布局LinearLayout区域
monitor_area1.setVisibility(View.VISIBLE);//显示控件
monitor_area1.setVisibility(View.INVISIBLE);//隐藏控件
View.VISIBLE--->可见
View.INVISIBLE--->不可见,但这个View仍然会占用在xml文件中所分配的布局空间,不重新layout
View.GONE---->不可见,但这个View在ViewGroup中不保留位置,会重新layout,不再占用空间,那后面的view就会取代他的位置,
Android_tablayout相关推荐
最新文章
- 重新定位svn地址的方法(windows和linux),svn switch(sw)的帮助信息
- linux中如何查找文件中内容
- 关于VS2017 添加 EF的MVC控制器报错的解决方法
- HDU4372(第一类斯特林数)
- Navicat 10 for SQL Server - 绿色中文版
- 2021年度训练联盟热身训练赛第一场 H题On Average They‘re Purple(BFS)
- G20杭州峰会上云 实现0安全事件
- Python中的字符串与字符编码:编码和转换问题
- Linux系统下通过命令行对mysql数据进行备份和还原
- 用TF实现线性回归模型。
- 智能语音识别究竟是如何实现的?
- 腾讯实习生招聘失败经历分享
- 【DVB】【Cert】DVD相关认证简介
- 腾讯云服务器入门使用流程 新手必看教程
- 十人即开团,分销商城全民拼购模式解析
- Multi-Objective Computation Sharing in Energy and Delay Constrained Mobile Edge Computing
- 重装win7系统显示:无法安装在gpt硬盘上
- 我是如何在毕业不久只用1年就升为开发组长的
- 源码之 LifeCycleOwner
- Could not determine artifacts for“xxx“No cached version available for offline mode
热门文章
- 07 降低cache不命中率
- Elasticsearch目录结构简单介绍
- Python 彩色图转换成素描图(灰度图)
- 基于STM32结合CubeMX学习Free-RT-OS的源码之任务创建
- 智融SW3556 SW3516 快充协议 PD3.0 PD3.1协议芯片
- 人事管理系统html,JSP实现简单人事管理系统
- 基于微信旅游景区购票小程序毕业设计毕设作品(1)开发概要
- 微软官宣!与英伟达签署10年游戏合作;星巴克推出橄榄油咖啡 | 美通企业日报...
- [GUET-CTF2019]BabyRSA 题解
- 树莓派4B 8G安装日志(2)——硬件操控