当前位置:网站首页>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));
}
}边栏推荐
- Selenium element positioning (2)
- Win10 add file extension
- Redis key operation
- Basic operations of database and table ----- set the fields of the table to be automatically added
- 剑指 Offer 38. 字符串的排列
- Redis string type
- 【网络攻防实训习题】
- [flask] official tutorial -part2: Blueprint - view, template, static file
- PHP campus financial management system for computer graduation design
- 【Flask】获取请求信息、重定向、错误处理
猜你喜欢

Basic operations of databases and tables ----- non empty constraints

【Flask】官方教程(Tutorial)-part1:项目布局、应用程序设置、定义和访问数据库

leetcode-两数之和

Mongodb problem set

selenium 等待方式

Kubernetes stateless application expansion and contraction capacity
![[width first search] Ji Suan Ke: Suan tou Jun goes home (BFS with conditions)](/img/ec/7fcdcbd9c92924e765d420f7c71836.jpg)
[width first search] Ji Suan Ke: Suan tou Jun goes home (BFS with conditions)

Jisuanke - t2063_ Missile interception

leetcode3、实现 strStr()

Computer graduation design PHP part-time recruitment management system for College Students
随机推荐
Computer graduation design PHP enterprise staff training management system
SPI communication protocol
Selenium waiting mode
安装Redis
leetcode-两数之和
Campus second-hand transaction based on wechat applet
插卡4G工业路由器充电桩智能柜专网视频监控4G转以太网转WiFi有线网速测试 软硬件定制
Ali test open-ended questions
TrueType字体文件提取关键信息
01. Go language introduction
Accelerating spark data access with alluxio in kubernetes
A basic lintcode MySQL database problem
[Jiudu OJ 09] two points to find student information
module ‘tensorflow. contrib. data‘ has no attribute ‘dataset
I like Takeshi Kitano's words very much: although it's hard, I will still choose that kind of hot life
Basic operations of databases and tables ----- primary key constraints
Comments on flowable source code (XXXV) timer activation process definition processor, process instance migration job processor
Folio. Ink is a free, fast and easy-to-use image sharing tool
NumPy 数组索引 切片
Flutter Doctor:Xcode 安装不完整