android tabwidget的现有补丁允许左侧的选项卡?
我的雇主让我工作在一个非常具体的UI需求的android应用程序上。具体而言,我们需要一个与TabWidget接口完全相同的接口。但是,在左侧有选项卡是绝对必须的。我们不打算将此应用程序部署到任何Android手机,它的内部设备,因此没有任何问题违反Android平台可能具有的任何设计考虑因素。android tabwidget的现有补丁允许左侧的选项卡?
我们已经有了一个工作原型,可以使用焦点侦听器和列表视图的组合来将我们需要的功能集合在一起。这并不美妙,我们对此尚不十分自信,但它暂时有效。
我们真正想要的是抛弃所有的原型UI代码,以换取使用内置的TabWidget。但是,由于TabWidget被硬编码为只能在顶部使用标签,所以这不是一个真正的选择。
因此,我们希望有人在那里有一个补丁,或一组补丁,或者一个自定义类,它可以通过侧面的选项卡来处理TabWidget功能?
和被硬编码为是在顶部标签的具体功能是
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);
}
如果任何人有任何的信息,我会非常感激。
我有这个问题,底部的标签。我最终只是复制了所有选项卡背景可绘制,并使用带有状态可绘制和文本颜色的按钮,它们看起来像是在主UI窗格中控制ViewFlipper以在视图之间切换的选项卡。
(请注意,我添加了一个更好的答案进一步下跌,过去就行了。我的情况下,留在这上面一个是更好地满足别人的需求。)
是啊,我一直在处理与同样的问题。我有一个有点笨重的解决方案。我注意到你可以使用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得到滚动的东西。好极了!
这看起来应该可以工作,但我得到奇怪的结果。我复制并粘贴你的XML。对我来说,它将标签放在右侧,但标签仍然是水平排列的,下方有一个很大的空白空间,标签内容在左侧。这是非常丑陋的,我无法想象这就是你的意图? – 2011-09-15 21:30:44
好吧,不是最初,但它最终为我的目的运作良好。也许是因为我有一台平板电脑,所以有足够的空间让标签保持水平。另外,我需要将相当数量的选项卡放入该空间,所以无论如何它对我来说都更好。对不起,这不是你正在寻找的。不管怎样,你仍然可以尝试与对象旋转混合,也许与此组合。祝你好运! – Erhannis 2011-09-18 04:20:45
这是一个真正的耻辱,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