2011-06-23 11 views
1

Dolphin HDのようなタブブラウジングをシミュレートするアプリケーションを開発したいと考えています。以下は、私がUIを作成するために使用したXMLファイルです。Tab host autoscroll - Programmatically

私のクエリは、私はイルカHDのような固定サイズのタブを取得することはできませんよ、

  1. です。
  2. 4〜5個程度のタブを作成したときに、プログラムごとにフォーカスを新しいタブに設定し、現在のビューにスクロールしたいと思っています。

enter image description here

同様のクエリは、以下のリンクに掲載されましたが、そのは Android - Programmatic scrolling of TabWidget

で新しいタブメソッドを追加...まだ働いていない、私は上記のリンクで説明したように、以下の行を挿入しようとしました...。それは...

 tabHost.setFocusableInTouchMode(true); 
    tabHost.setCurrentTab(z); 
    tabHost.setFocusable(true); 
    //Vinod 
    for (i = 0; i < z; i++) { 
     getTabWidget().getChildAt(i).setFocusableInTouchMode(true); 
     } 

XMLファイルを動作しませんでした: -

<?xml version="1.0" encoding="utf-8"?> 

    <TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@android:id/tabhost" 
       android:layout_width="wrap_content" 
       android:layout_height="fill_parent"> 


    <LinearLayout 
       android:orientation="vertical" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:padding="5dp"> 

    <RelativeLayout 
       android:orientation="horizontal" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content"> 

    <HorizontalScrollView android:layout_width="420px" 
       android:id="@+id/tab1" 
       android:layout_height="wrap_content" 
       android:fillViewport="true" 
       android:scrollbars="none"> 

    <TabWidget 
       android:id="@android:id/tabs" 
       android:layout_width="10px" 
       android:layout_height="wrap_content" 
       android:tag="tabPane"> 
    </TabWidget> 
    </HorizontalScrollView> 
    <ImageButton 
       android:background="@android:color/transparent" 
       android:layout_marginTop="10px" 
       android:id="@+id/add_btn" 
       android:layout_height="70px" 
       android:layout_width="70px" 
       android:src="@android:drawable/ic_menu_add" 
       android:layout_toRightOf="@id/tab1"/> 
    </RelativeLayout> 

    <RelativeLayout 
       android:orientation="vertical" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content"> 
    <EditText 
       android:id="@+id/address_bar" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentTop="true" 
       android:layout_marginTop="10px" 
       android:layout_width="fill_parent" 
       android:layout_height="70px"/> 

     </RelativeLayout> 
     <FrameLayout 
       android:id="@android:id/tabcontent" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:padding="2dp" /> 
     </LinearLayout> 
     </TabHost> 

答えて

0

遅延がタイミングによるものであった、これだけ遅延は完全に大丈夫に動作します。

HorizontalScrollView hv = (HorizontalScrollView)findViewById(id.tab1); 

//hv.fullScroll(HorizontalScrollView.FOCUS_RIGHT); 
for (i = 0; i < z; i++) { 
    getTabWidget().getChildAt(i).setFocusableInTouchMode(true); 
} 

hv.postDelayed(new Runnable() { 
    public void run() 
    { 
     HorizontalScrollView hv = (HorizontalScrollView)findViewById(id.tab1); 
     hv.fullScroll(HorizontalScrollView.FOCUS_RIGHT); 
    } 
}, 100L);