当前位置:网站首页>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));
}
}
边栏推荐
- 【Flask】官方教程(Tutorial)-part3:blog蓝图、项目可安装化
- [flask] official tutorial -part2: Blueprint - view, template, static file
- 【Flask】官方教程(Tutorial)-part1:项目布局、应用程序设置、定义和访问数据库
- TrueType字体文件提取关键信息
- [ssrf-01] principle and utilization examples of server-side Request Forgery vulnerability
- 插卡4G工业路由器充电桩智能柜专网视频监控4G转以太网转WiFi有线网速测试 软硬件定制
- 0211 embedded C language learning
- 【Flask】响应、session与Message Flashing
- Competition question 2022-6-26
- Get the relevant information of ID card through PHP, get the zodiac, get the constellation, get the age, and get the gender
猜你喜欢
[Jiudu OJ 09] two points to find student information
Poj2315 football games
Basic operations of databases and tables ----- unique constraints
Computer graduation design PHP animation information website
干货!通过软硬件协同设计加速稀疏神经网络
Open source | Ctrip ticket BDD UI testing framework flybirds
[depth first search] Ji Suan Ke: Betsy's trip
国家级非遗传承人高清旺《四大美人》皮影数字藏品惊艳亮相!
[flask] official tutorial -part1: project layout, application settings, definition and database access
500 lines of code to understand the principle of mecached cache client driver
随机推荐
【Flask】官方教程(Tutorial)-part3:blog蓝图、项目可安装化
dried food! Accelerating sparse neural network through hardware and software co design
It's wrong to install PHP zbarcode extension. I don't know if any God can help me solve it. 7.3 for PHP environment
安装Redis
MCU lightweight system core
NiO related knowledge (II)
Basic operations of databases and tables ----- default constraints
leetcode3、實現 strStr()
Pangolin Library: subgraph
I like Takeshi Kitano's words very much: although it's hard, I will still choose that kind of hot life
Basic operations of database and table ----- delete data table
Open source | Ctrip ticket BDD UI testing framework flybirds
阿里测开面试题
Visualstudio2019 compilation configuration lastools-v2.0.0 under win10 system
【Flask】静态文件与模板渲染
[network attack and defense training exercises]
Competition question 2022-6-26
01.Go语言介绍
Shutter doctor: Xcode installation is incomplete
02.Go语言开发环境配置