【问题标题】:Tab host autoscroll – Programmatically选项卡主机自动滚动 - 以编程方式
【发布时间】:2011-07-06 22:08:40
【问题描述】:

我想开发一个像 Dolphin HD 一样模拟标签浏览的应用程序。下面是我用来创建 UI 的 XML 文件。

我的查询是,

  1. 我无法获得像 dolphin HD 这样的固定尺寸标签。
  2. 当我创建了大约 4-5 个选项卡后,现在我想以编程方式将焦点设置到新选项卡并将其滚动到当前视图。

类似的查询已发布在以下链接中,但它仍然无法正常工作...... 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>

【问题讨论】:

    标签: android-tabhost


    【解决方案1】:

    延迟是由于时间问题,所以只是延迟就可以了。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-22
      • 1970-01-01
      • 1970-01-01
      • 2017-05-26
      • 1970-01-01
      • 1970-01-01
      • 2011-12-09
      • 1970-01-01
      相关资源
      最近更新 更多