Android中两种实现底部Tab的方法,在一家公司干多长时间跳槽才合适

在LinerLayout布局里面嵌套FrameLayout和RelativeLayout布局,将TabWidget放置在RelativeLayout里面,之后设置RelativeLayout的android:layout_alignParentBottom=“true” 属性,这个属性的功能是将TabWidget置于父元素(也就是LinerLayout)的底部。这样就能将Tab置于底部了。

  1. <?xml version\="1.0" encoding\="utf-8"?>
  2. <LinearLayout

  3.  xmlns:android\="http://schemas.android.com/apk/res/android" 
    
  4.  android:orientation\="vertical" 
    
  5.  android:layout\_width\="fill\_parent" 
    
  6.  android:layout\_height\="fill\_parent"\> 
    
  7.  <TabHost 
    
  8.      android:id\="@+id/tabhost" 
    
  9.      android:layout\_width\="fill\_parent" 
    
  10.      android:layout\_height\="fill\_parent"\> 
    
  11.      <FrameLayout 
    
  12.          android:id\="@android:id/tabcontent" 
    
  13.          android:layout\_width\="fill\_parent" 
    
  14.          android:layout\_height\="fill\_parent" 
    
  15.          android:paddingBottom\="62px" 
    
  16.          \> 
    
  17.          <TextView 
    
  18.              android:id\="@+id/tab1" 
    
  19.              android:layout\_width\="fill\_parent" 
    
  20.              android:layout\_height\="fill\_parent" 
    
  21.              android:text\="这是TabOne" 
    
  22.              /> 
    
  23.          <TextView 
    
  24.              android:id\="@+id/tab2" 
    
  25.              android:layout\_width\="fill\_parent" 
    
  26.              android:layout\_height\="fill\_parent" 
    
  27.              android:text\="这是TabTwo"/> 
    
  28.      </FrameLayout\> 
    
  29.      <RelativeLayout 
    
  30.          android:layout\_width\="fill\_parent" 
    
  31.          android:layout\_height\="fill\_parent" 
    
  32.          \> 
    
  33.          <TabWidget 
    
  34.              android:id\="@android:id/tabs" 
    
  35.              android:layout\_alignParentBottom\="true" 
    
  36.              android:layout\_width\="fill\_parent" 
    
  37.              android:layout\_height\="65.0px"   
    
  38.              android:background\="@drawable/tab\_bg"             
    
  39.              /> 
    
  40.      </RelativeLayout\> 
    
  41.  </TabHost\> 
    
  42. </LinearLayout>

main.xml

  1. <?xml version\="1.0" encoding\="utf-8"?>
  2. <LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”

  3.  android:orientation\="vertical" 
    
  4.  android:layout\_width\="fill\_parent" 
    
  5.  android:layout\_height\="fill\_parent" 
    
  6.  \> 
    
  7. <TextView

  8.  android:layout\_width\="fill\_parent"   
    
  9.  android:layout\_height\="wrap\_content"   
    
  10.  android:text\="@string/hello" 
    
  11.  /> 
    
  12. </LinearLayout>

TabHostActivity.java

  1. package com.lingdududu.test;

  2. import android.app.Activity;

  3. import android.os.Bundle;

  4. import android.widget.TabHost;

  5. public class TabHostActivity extends Activity {

  6.  public void onCreate(Bundle savedInstanceState) {  
    
  7.      super.onCreate(savedInstanceState);  
    
  8.      setContentView(R.layout.tabs);  
    
  9.      TabHost tabs=(TabHost)findViewById(R.id.tabhost);  
    
  10.      tabs.setup();  
    
  11.      TabHost.TabSpec spec=tabs.newTabSpec("tag1");  
    
  12.      spec.setContent(R.id.tab1);  
    
  13.      spec.setIndicator("TabOne");  
    
  14.      tabs.addTab(spec);  
    
  15.      spec=tabs.newTabSpec("tag2");  
    
  16.      spec.setContent(R.id.tab2);  
    
  17.      spec.setIndicator("TabTwo");  
    
  18.      tabs.addTab(spec);  
    
  19.      tabs.setCurrentTab(0);  
    
  20.  }  
    
  21. }

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级安卓工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Android移动开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
img
img
img
img

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
img

片转存中…(img-31SuomQ7-1710918002754)]
[外链图片转存中…(img-gHePLNXv-1710918002754)]

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
[外链图片转存中…(img-oUiVWG5R-1710918002755)]

  • 11
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 Vue 实现 tab 切换内容有多种方法,其比较常用的有以下几种: 1. 使用 `v-show` 或 `v-if` 指令 这是最简单的一种方法,通过 `v-show` 或 `v-if` 指令来判断当前选tab,然后对应显示或隐藏对应的内容。例如: ```html <div> <button @click="activeTab = 'tab1'">Tab1</button> <button @click="activeTab = 'tab2'">Tab2</button> <button @click="activeTab = 'tab3'">Tab3</button> </div> <div v-show="activeTab === 'tab1'">Tab1 Content</div> <div v-show="activeTab === 'tab2'">Tab2 Content</div> <div v-show="activeTab === 'tab3'">Tab3 Content</div> ``` 2. 使用 `v-bind:class` 指令 通过 `v-bind:class` 指令来给选tab 添加一个激活状态的 CSS 类,然后根据这个类来控制对应的内容的显示或隐藏。例如: ```html <div> <button :class="{ 'active': activeTab === 'tab1' }" @click="activeTab = 'tab1'">Tab1</button> <button :class="{ 'active': activeTab === 'tab2' }" @click="activeTab = 'tab2'">Tab2</button> <button :class="{ 'active': activeTab === 'tab3' }" @click="activeTab = 'tab3'">Tab3</button> </div> <div :class="{ 'show': activeTab === 'tab1' }">Tab1 Content</div> <div :class="{ 'show': activeTab === 'tab2' }">Tab2 Content</div> <div :class="{ 'show': activeTab === 'tab3' }">Tab3 Content</div> ``` 3. 使用组件 将每个 tab 对应的内容封装成一个组件,然后在父组件通过切换组件来实现 tab 切换。这种方法相对于前两种方法更加灵活和可维护,但需要进行组件的拆分和引用。例如: ```html <div> <button @click="activeTab = 'tab1'">Tab1</button> <button @click="activeTab = 'tab2'">Tab2</button> <button @click="activeTab = 'tab3'">Tab3</button> </div> <tab1 v-if="activeTab === 'tab1'"></tab1> <tab2 v-if="activeTab === 'tab2'"></tab2> <tab3 v-if="activeTab === 'tab3'"></tab3> ``` 以上三种方法均可实现 tab 切换内容,选择哪种方法最好取决于具体的业务场景和需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值