I am a newbie in Android, how can I do something like that.
I extend TabActivity when to create Tabs like this but without that header.
答案 0 :(得分:0)
如果要实现此处发布的视图,可以自行编写视图代码:
标题位于顶部,标题下方需要TabHost
,在TabHost
下方,您将viewpager包含两个片段以显示您的数据,您可以控制viewpager
单击标签时,使用方法setCurrentItem
进行1}}。
答案 1 :(得分:0)
试试这段代码 MainActivity
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBarActivity;
import com.viewpagerindicator.CirclePageIndicator;
public class LauncherActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launcher);
pager.setAdapter(new GuidePagerAdapter(getSupportFragmentManager()));
indicator.setViewPager(pager);
}
}
ativity_main
<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:background="@drawable/background"
android:orientation="vertical"
>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#80000000"
android:orientation="vertical" >
<com.viewpagerindicator.CirclePageIndicator
android:id="@+id/indicator"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp" />
</LinearLayout>
</LinearLayout>
适配器
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
public class GuidePagerAdapter extends FragmentStatePagerAdapter {
public GuidePagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int pos) {
if (pos == 0)
return new Fragment1();
else
return new Fragment2();
}
@Override
public int getCount() {
return 2;
}
}
您可以在main_activity上添加两个选项卡,然后单击选项卡更改适配器中的片段。