4
我需要用空格分隔標籤按鈕,我試圖設置邊緣視圖,然後將它們添加爲標籤,但它不起作用,我也想添加空視圖作爲分隔線,但還沒有嘗試過,是有沒有任何標準的做法,或任何調整,可以實現相同的效果?如何在Android中的標籤按鈕之間添加空間?
謝謝!
我需要用空格分隔標籤按鈕,我試圖設置邊緣視圖,然後將它們添加爲標籤,但它不起作用,我也想添加空視圖作爲分隔線,但還沒有嘗試過,是有沒有任何標準的做法,或任何調整,可以實現相同的效果?如何在Android中的標籤按鈕之間添加空間?
謝謝!
這裏的方式:
TabWidget tabWidget = (TabWidget) findViewById(android.R.id.tabs);
final int tabChildrenCount = tabWidget.getChildCount();
View currentView;
for (int i = 0; i < tabChildrenCount; i++) {
currentView = tabWidget.getChildAt(i);
LinearLayout.LayoutParams currentLayout =
(LinearLayout.LayoutParams) currentView.getLayoutParams();
currentLayout.setMargins(0, 5, 5, 0);
}
tabWidget.requestLayout();
這是真的連我的問題很好的解決!非常感謝!我使用它來實現小部件的第一個和最後一個項目之前的空間,以便可以將它們滾動到中心可見而不增加額外的(並且令人不安的,因爲小部件不會察覺到這些愚蠢的東西)隱形按鈕。
//pump up space for first entry on the left and last entry on the right!
Display display = getWindowManager().getDefaultDisplay();
//Point size = new Point();
int width = display.getWidth();
View currentView = mTabHost.getTabWidget().getChildAt(0);
LinearLayout.LayoutParams currentLayout = (LinearLayout.LayoutParams) currentView.getLayoutParams();
currentLayout.setMargins(currentLayout.leftMargin + width/2, currentLayout.topMargin, currentLayout.rightMargin, currentLayout.bottomMargin);
currentView = mTabHost.getTabWidget().getChildAt(mTabHost.getTabWidget().getChildCount()-1);
currentLayout = (LinearLayout.LayoutParams) currentView.getLayoutParams();
currentLayout.setMargins(currentLayout.leftMargin, currentLayout.topMargin, currentLayout.rightMargin + width/2, currentLayout.bottomMargin);
mTabHost.getTabWidget().requestLayout();
謝謝,我會試試看。 – hzxu 2011-05-26 20:58:25
我試過了,它確實有用,謝謝! – hzxu 2011-05-26 23:08:47
@Kamen:謝謝......它工作完美! :) +1 – Hiral 2012-03-02 07:33:59