2010-08-16 46 views
5

我的僱主讓我工作在一個非常具體的UI需求的android應用程序上。具體而言,我們需要一個與TabWidget接口完全相同的接口。但是,在左側有選項卡是絕對必須的。我們不打算將此應用程序部署到任何Android手機,它的內部設備,因此沒有任何問題違反Android平臺可能具有的任何設計考慮因素。android tabwidget的現有補丁允許左側的選項卡?

我們已經有了一個工作原型,可以使用焦點偵聽器和列表視圖的組合來將我們需要的功能集合在一起。這並不美妙,我們對此尚不十分自信,但它暫時有效。

我們真正想要的是拋棄所有的原型UI代碼,以換取使用內置的TabWidget。但是,由於TabWidget被硬編碼爲只能在頂部使用標籤,所以這不是一個真正的選擇。

因此,我們希望有人在那裏有一個補丁,或一組補丁,或者一個自定義類,它可以通過側面的選項卡來處理TabWidget功能?

爲TabWidget相關的代碼是在這裏:http://www.google.com/codesearch/p?hl=en#uX1GffpyOZk/core/java/android/widget/TabWidget.java&q=android%20package:git://android.git.kernel.org%20lang:java%20tabwidget&sa=N&cd=1&ct=rc

和被硬編碼爲是在頂部標籤的具體功能是

private void initTabWidget() { 
    setOrientation(LinearLayout.HORIZONTAL); 
    mGroupFlags |= FLAG_USE_CHILD_DRAWING_ORDER; 

    final Context context = mContext; 
    final Resources resources = context.getResources(); 

    if (context.getApplicationInfo().targetSdkVersion <= Build.VERSION_CODES.DONUT) { 
     // Donut apps get old color scheme 
     if (mLeftStrip == null) { 
      mLeftStrip = resources.getDrawable(
        com.android.internal.R.drawable.tab_bottom_left_v4); 
     } 
     if (mRightStrip == null) { 
      mRightStrip = resources.getDrawable(
        com.android.internal.R.drawable.tab_bottom_right_v4); 
     } 
    } else { 
     // Use modern color scheme for Eclair and beyond 
     if (mLeftStrip == null) { 
      mLeftStrip = resources.getDrawable(
        com.android.internal.R.drawable.tab_bottom_left); 
     } 
     if (mRightStrip == null) { 
      mRightStrip = resources.getDrawable(
        com.android.internal.R.drawable.tab_bottom_right); 
     } 
    } 

    // Deal with focus, as we don't want the focus to go by default 
    // to a tab other than the current tab 
    setFocusable(true); 
    setOnFocusChangeListener(this); 
} 

如果任何人有任何的信息,我會非常感激。

回答

1

我有這個問題,底部的標籤。我最終只是複製了所有選項卡背景可繪製,並使用帶有狀態可繪製和文本顏色的按鈕,它們看起來像是在主UI窗格中控制ViewFlipper以在視圖之間切換的選項卡。

+0

這是一個真正的恥辱,TabActivty無法處理底部或旁邊的標籤本身。我不明白爲什麼這不是內置的。 我找到了一個關於android bug跟蹤器的bug報告,但是沒有任何跡象表明這會在很短的時間內發揮作用。 http://code.google.com/p/android/issues/detail?id=3862&can=1&q=TabWidget&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars#makechanges – 2010-08-17 20:04:41

1

(請注意,我添加了一個更好的答案進一步下跌,過去就行了。我的情況下,留在這上面一個是更好地滿足別人的需求。)

是啊,我一直在處理與同樣的問題。我有一個有點笨重的解決方案。我注意到你可以使用setRotate幾乎旋轉任何View。不幸的是,這隻會旋轉其圖像或其他內容,並未完全處理問題或放置,尺寸或對齊方式。即便如此,我已經設法湊齊一些補償它的東西,儘管它只完成了一半(如果旋轉到縱向方向,則不太合適)。每當平板電腦旋轉或佈局得到重新安排或不管什麼時,都會調用以下內容。

private LinearLayout llMain; 
private LinearLayout ll1; 
private LinearLayout mainView; 
private TabHost myTabHost; 

public void setStuff() { 
    Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay(); 
    if (display.getOrientation() == 0 || display.getOrientation() == 2) { 
     ViewGroup.LayoutParams lp = myTabHost.getLayoutParams(); 
     int top = 0; 
     int left = 0; 
     int height = 696; 
     int width = 1280; 
     int centerx = (width/2) + left; 
     int centery = (height/2) + top; 
     lp.height = width; 
     lp.width = height; 
     myTabHost.setLayoutParams(lp); 
     myTabHost.setTranslationX(centerx - (height/2)); 
     myTabHost.setTranslationY(centery - (width/2)); 
     lp = mainView.getLayoutParams(); 
     lp.width = 1280; 
     lp.height = 696; 
     mainView.setLayoutParams(lp); 
     lp = llMain.getLayoutParams(); 
     lp.width = 1280; 
     lp.height = 696; 
     llMain.setLayoutParams(lp); 

     ll1.setRotation(-90); 
     lp = ll1.getLayoutParams(); 
     lp.height = 696; 
     lp.width = 1141; 
     ll1.setLayoutParams(lp); 
     left = 0; 
     top = 0; 
     height = 696; 
     width = 1141; 
     centerx = (width/2) + left; 
     centery = (height/2) + top; 
     ll1.setTranslationX(centery - (width/2)); 
     ll1.setTranslationY(centerx - (height/2)); 
     //ll1.setTranslationX(tx); 
     //ll1.setTranslationY(ty); 
    } else { 
     ViewGroup.LayoutParams lp = myTabHost.getLayoutParams(); 
     int top = 0; 
     int left = 0; 
     int height = 1280; 
     int width = 696; 
     int centerx = (width/2) + left; 
     int centery = (height/2) + top; 
     lp.height = width; 
     lp.width = height; 
     myTabHost.setLayoutParams(lp); 
     myTabHost.setTranslationX(centerx - (height/2)); 
     myTabHost.setTranslationY(centery - (width/2)); 
     lp = mainView.getLayoutParams(); 
     lp.width = 696; 
     lp.height = 1280; 
     mainView.setLayoutParams(lp); 
     lp = llMain.getLayoutParams(); 
     lp.width = 696; 
     lp.height = 1280; 
     llMain.setLayoutParams(lp); 

     ll1.setRotation(-90); 
     lp = ll1.getLayoutParams(); 
     lp.height = 1141; 
     lp.width = 696; 
     ll1.setLayoutParams(lp); 
     left = 0; 
     top = 0; 
     height = 1141; 
     width = 696; 
     centerx = (width/2) + left; 
     centery = (height/2) + top; 
     ll1.setTranslationX(centery - (width/1)); 
     ll1.setTranslationY(centerx - (height/1)); 
     //ll1.setTranslationX(tx); 
     //ll1.setTranslationY(ty); 
    } 
} 

@Override 
public void onConfigurationChanged(Configuration newConfig) { 
    super.onConfigurationChanged(newConfig); 
    setStuff(); 
    //setContentView(R.layout.main); 
} 

llMain contains mainView contains myTabHost contains ll1;你需要在初始化代碼中分配它們。這個想法是TabHost順時針旋轉,並且它的尺寸必須手動交換,以便其容器現在知道它是不同的大小/形狀,否則邊緣會被切斷。此外,它還會進行一些計算,以便圍繞正確的點進行旋轉,或者至少結束在正確的位置。結果並不總是有意義的,所以我只是改變了東西,直到它工作,至少在風景模式下。 TabHost的內容也被旋轉,所以在那裏有代碼讓它旋轉回來,至少是第一個標籤,它是ll1。其他選項卡需要同樣向後旋轉。我弄了一會兒,可能有些東西是不必要的。例如,mainView。我認爲這並不需要在那裏。哦,如果TabHost位於不同的地方,則需要以某種方式調整數字。祝你好運。無論如何,我希望這有助於某人。人,Android的圖形用戶界面如此加重......我希望他們能夠修復它....不過,我承認儘管存在所有的障礙和挫折,任何組件的旋轉都是很酷。我只希望一切都像你期望的那樣工作。


嘿,我只是想出瞭如何讓它做到這一點!標籤留的水平,這樣可能會或可能不會是一件好事,這取決於你想要什麼,但無論如何:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <TabHost android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent"> 
     <LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> 
      <FrameLayout android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_weight="1" android:id="@android:id/tabcontent"></FrameLayout> 
      <ScrollView android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:fillViewport="true" 
       android:scrollbars="none">   
       <TabWidget android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:id="@android:id/tabs"></TabWidget> 
      </ScrollView> 
     </LinearLayout> 
    </TabHost> 

</LinearLayout> 

該XML文件定義了右邊的標籤的空tabhost。只需在代碼中添加標籤;有關於此的帖子。複製/修改/做任何你需要做的事情來使它適合你的需求。另外,因爲它很酷,我在tabwidget周圍添加了一個滾動視圖,所以如果你有太多的標籤,它會自動允許滾動。如果你不想要它,就擺脫它。主要從http://java.dzone.com/articles/scrolling-tabs-android得到滾動的東西。好極了!

+0

這看起來應該可以工作,但我得到奇怪的結果。我複製並粘貼你的XML。對我來說,它將標籤放在右側,但標籤仍然是水平排列的,下方有一個很大的空白空間,標籤內容在左側。這是非常醜陋的,我無法想象這就是你的意圖? – 2011-09-15 21:30:44

+0

好吧,不是最初,但它最終爲我的目的運作良好。也許是因爲我有一臺平板電腦,所以有足夠的空間讓標籤保持水平。另外,我需要將相當數量的選項卡放入該空間,所以無論如何它對我來說都更好。對不起,這不是你正在尋找的。不管怎樣,你仍然可以嘗試與對象旋轉混合,也許與此組合。祝你好運! – Erhannis 2011-09-18 04:20:45