开发者

Tab host autoscroll – Programmatically

开发者 https://www.devze.com 2023-03-14 16:53 出处:网络
I want to develop an application simulating the tab browsing like Dolphin HD. Below is the XML file I have used to create the UI.

I want to develop an application simulating the tab browsing like Dolphin HD. Below is the XML file I have used to create the UI.

My queries are,

  1. I am not able to get the fixed size tab like dolphin HD.
  2. When I have created around 4-5 tabs, now I want to programmatically set the focus to new tab and scroll it to the current view.

Tab host autoscroll – Programmatically

Similar query was posted in the below link, but its not working still… Android - Programmatic scrolling of TabWidget

In add new tab method, I tried inserting the below lines as mentioned in the above link…. but it didn’t work…

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

XML file:-

<?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>


The delay was due to timing, so just a delay would work perfectly alright.

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); 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号