java - Tabhost 中没有动画/选择

标签 java android android-layout animation tabs

我正在尝试实现一个选项卡 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/

相关文章:

java - Google GIN、GWT 和 com.google.inject.Inject(可选=true)不起作用

Android ListView 自定义适配器

java - 由二进制 XML 文件引起的 IllegalArgumentException (Android)

android - Android工具栏中是否可以同时拥有后退按钮和菜单按钮?

android - 如何设置看起来像 "cards"的 TextView 的样式?

android - 如何消除子元素中的父填充

android - 动 Canvas 局的背景颜色变化

java - Jackson 对第 3 方类进行序列化和反序列化,无需编写自定义序列化器和/或反序列化器

java - 如何使用Springboot REST从数据库下载记录

java - Excel 导出中的乱码