当前位置:网站首页>Use Scrollview and tabhost to realize vertical scrollbars and tabs
Use Scrollview and tabhost to realize vertical scrollbars and tabs
2022-07-06 02:05:00 【Standing on the shoulders of giants, review the past and know t】
1 Scroll bar
Scroll view ScrollView yes FrameLayout Subclasses of . By default, the scroll bar is not displayed , Show after dragging , The scroll bar disappears after you stop dragging .
Vertical scroll bar :ScrollView
Horizontal scroll bar :HorizontalScrollView
Add a scrolling view in two ways :
1 xml Layout file
<ScrollView
android:id="@id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_parent" >
<!-- Components to add scroll bars -->
</ScrollView>
2 Code
(1)new ScrollView()
(2) Pass the components that need to add scroll bars addView() Add to scroll view
(3) Add a scrolling view to the layout manager
ScrollView: Realize vertical scroll bar
MainActivity.java
public class MainActivity extends AppCompatActivity {
LinearLayout linearLayout, linearLayout2;
ScrollView scrollView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
linearLayout = (LinearLayout) findViewById(R.id.ll);
linearLayout2 = new LinearLayout(MainActivity.this);
// Set to portrait
linearLayout2.setOrientation(LinearLayout.VERTICAL);
scrollView = new ScrollView(MainActivity.this);
// Add a scrolling view component to the default layout
linearLayout.addView(scrollView);
// Add a new layout to the scroll view component
scrollView.addView(linearLayout2);
TextView textView = new TextView(MainActivity.this);
textView.setText(R.string.cidian);
// Add... To the new layout TextView Components
linearLayout2.addView(textView);
}
}
https://github.com/hanyuhang-hz/android-demos
2 tab
Tabs are used to implement a multi tab user interface . Use the tabs , Follow the following steps to achieve :
(1) Add the required to implement the tab in the layout file TabHost,LinearLayout,TabWidget and FrameLayout.
(2) Write the for each tab xml Layout file .
(3) initialization TabHost Components .
(4) by TabHost Add tabs .
TabHost: Implementation tab
MainActivity.java
public class MainActivity extends AppCompatActivity {
private TabHost tabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tabHost = (TabHost) findViewById(android.R.id.tabhost);
tabHost.setup();
LayoutInflater inflater = LayoutInflater.from(this);
inflater.inflate(R.layout.tab1, tabHost.getTabContentView());
inflater.inflate(R.layout.tab2,tabHost.getTabContentView());
// Add the first tab
tabHost.addTab(tabHost.newTabSpec("tab1")
.setIndicator("tab1")
.setContent(R.id.linearlayout1));
// Add a second tab
tabHost.addTab(tabHost.newTabSpec("tab2")
.setIndicator("tab2")
.setContent(R.id.linearlayout2));
}
}
边栏推荐
- Computer graduation design PHP part-time recruitment management system for College Students
- 【Flask】静态文件与模板渲染
- Campus second-hand transaction based on wechat applet
- Comments on flowable source code (XXXV) timer activation process definition processor, process instance migration job processor
- How to set an alias inside a bash shell script so that is it visible from the outside?
- 使用npm发布自己开发的工具包笔记
- NLP第四范式:Prompt概述【Pre-train,Prompt(提示),Predict】【刘鹏飞】
- A Cooperative Approach to Particle Swarm Optimization
- Basic operations of databases and tables ----- non empty constraints
- Computer graduation design PHP enterprise staff training management system
猜你喜欢
Card 4G industrial router charging pile intelligent cabinet private network video monitoring 4G to Ethernet to WiFi wired network speed test software and hardware customization
同一个 SqlSession 中执行两条一模一样的SQL语句查询得到的 total 数量不一样
Leetcode3. Implement strstr()
Basic operations of databases and tables ----- primary key constraints
NumPy 数组索引 切片
PHP campus financial management system for computer graduation design
NLP fourth paradigm: overview of prompt [pre train, prompt, predict] [Liu Pengfei]
Leetcode3, implémenter strstr ()
Blue Bridge Cup embedded_ STM32 learning_ Key_ Explain in detail
Poj2315 football games
随机推荐
Basic operations of databases and tables ----- non empty constraints
【Flask】获取请求信息、重定向、错误处理
Folio. Ink is a free, fast and easy-to-use image sharing tool
Numpy array index slice
[network attack and defense training exercises]
Using SA token to solve websocket handshake authentication
Cookie concept, basic use, principle, details and Chinese transmission
Win10 add file extension
PHP campus movie website system for computer graduation design
Basic operations of databases and tables ----- default constraints
Campus second-hand transaction based on wechat applet
GBase 8c数据库升级报错
module ‘tensorflow. contrib. data‘ has no attribute ‘dataset
剑指 Offer 12. 矩阵中的路径
Leetcode3. Implement strstr()
安装Redis
Regular expressions: examples (1)
Extracting key information from TrueType font files
Poj2315 football games
Paddle framework: paddlenlp overview [propeller natural language processing development library]