我正在尝试实现一个选项卡 View ,该选项卡 View 具有从一个 View 到另一个动画的良好渐变,并突出显示当前选项卡。目前我所能得到的只是基本的选项卡 View ,但可以即时切换选项卡并且不突出显示选择。这是我当前的代码:
package com.example.ex.test;
public class MainActivity extends navBar {
private FragmentTabHost mTabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("Tab1"),
smithingTable.class, null);
mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator("Tab2"),
smithingTable2.class, null);
mTabHost.addTab(mTabHost.newTabSpec("tab3").setIndicator("Tab3"),
Map.class, null);
}
}
同时在我的主要 Activity 中我有:
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TabWidget
android:id="@android:id/tabs"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0"/>
<FrameLayout
android:id="@+id/realtabcontent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
以 tab1 为例(tab2 相同,但略有不同)
<?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"
android:orientation="vertical"
tools:context=".DeviceFragment" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test1" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView3"
android:layout_gravity="center_horizontal"
android:src="@drawable/newcomer_map" />
最佳答案
我真的建议您使用Material Design Tabs,它已经有很好的过渡并且更可定制。
这是一个非常好的post以及如何实现
关于java - Tabhost 中没有动画/选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36111101/