0

我有一个布局。首先,我将讲述它。
1.TabHost 及以下 2.List
带有页眉和页脚。(页眉是一个View,膨胀布局)。

以下所有编码都在片段中。

这就是我制作 HeaderView 的方式:

View headerView;
headerView = ((LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.activity_first,null, false);

然后将 headerView 添加到 listView。

this.list_news.addHeaderView(headerView);

以下activity_first.xml用于为 headerView 充气。

activity_first.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

<include 
    android:id="@+id/content"
    layout="@layout/activity_main"
    android:layout_width="match_parent"
    android:layout_height="200dp"/>


</LinearLayout>

以下activity_main.xml用于在 activity_first.xml 中包含布局。

活动主.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res/net.top.ly3w"
    android:id="@+id/background_linear"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/photosload"
    android:orientation="vertical"
     >

    <ProgressBar
        android:id="@+id/progressBar1"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true" />

     <android.support.v4.view.ViewPager
        android:id="@+id/view_pager"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/circle_indicator"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_weight="1" />

    <net.top.ly3w.viewpager.CirclePageIndicator
        android:id="@+id/circle_indicator"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_marginTop="-40dp"
        android:padding="10dip" />

</RelativeLayout>

图片:

在此处输入图像描述

所以,现在我将描述我遇到的问题,哪里headerView看起来像幻灯片,在特定时间加载 url 图像的数量。它有单独的触摸事件。它适用于活动。但是当我在 tabhost 中使用它并且当我在幻灯片上滑动时,整个选项卡将移动到下一个选项卡。我不想滑动整个选项卡,而不是它,我只想滑动 headerView 中的下一张幻灯片。那么,我该如何实现呢?

使用以下代码设置选项卡:

TabSpec ts1 = setupTab(new TextView(this), "?");
        TabSpec ts2 = setupTab(new TextView(this), "-");
        TabSpec ts3 = setupTab(new TextView(this), "=");
        TabSpec ts4 = setupTab(new TextView(this), "?");
        TabSpec ts5 = setupTab(new TextView(this), "?");
        TabSpec ts6 = setupTab(new TextView(this), "?");

        mTabsAdapter.addTab(ts1, NewsOneActivity.class, null);
        mTabsAdapter.addTab(ts2, NewsTwoActivity.class, null);
        mTabsAdapter.addTab(ts3, NewsTwoActivity.class, null);
        mTabsAdapter.addTab(ts4, NewsTwoActivity.class, null);
        mTabsAdapter.addTab(ts5, NewsTwoActivity.class, null);
        mTabsAdapter.addTab(ts6, NewsSixActivity.class, null);

        public void addTab(TabHost.TabSpec tabSpec, Class<?> clss, Bundle args) {
            tabSpec.setContent(new DummyTabFactory(mContext));
            String tag = tabSpec.getTag();

            TabInfo info = new TabInfo(tag, clss, args);
            mTabs.add(info);
            mTabHost.addTab(tabSpec);
4

0 回答 0