Android中实现可滑动的Tab的3种方式

2019-12-10 20:11:09王旭

            v.setBackgroundColor(r.nextInt() >> 8 | 0xFF << 24);

            TextView txvAddress = (TextView) v.findViewById(R.id.textView1);
            txvAddress.setTextColor(r.nextInt() >> 8 | 0xFF << 24);
            txvAddress.setBackgroundColor(r.nextInt() >> 8 | 0xFF << 24);

            txvAddress.setText(b.getString("address", ""));
            return v;
        }

    }
}


布局:
复制代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://www.easck.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

 

    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>


3. 【推荐】第三种,使用 TabWidget + ViewPager 实现
该方法不错,推荐使用。

 

Android中实现可滑动的Tab的3种方式

Activity:

复制代码
package com.swordy.demo.android.fragment;

 

import java.util.Random;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;