对于Android tabwidget现有的补丁程序,以允许在左侧的选项卡?选项卡、补丁、程序、Android

2023-09-06 04:39:16 作者:爱自己么情敌

我的雇主是有我的Andr​​oid应用程序的工作非常具体的用户界面要求。具体而言,我们需要一个长相酷似一个TabWidget接口的接口。然而,具有在左手侧上的翼片是绝对必要的。我们不打算部署该应用程序的任何Android手机,它的一个内部设备,因此没有任何问题,违反任何设计考虑,Android平台可能。

My employer is having me work on an android application with very specific UI requirements. Specifically, we need an interface that looks exactly like a TabWidget interface. However, having the tabs on the left hand side is an absolute must. We aren't going to be deploying this application to any android phones, its for an in house device, and as such don't have any problem violating any design considerations that the android platform might have.

我们已经有一个工作原型,黑客在一起,我们需要用焦点侦听器和列表视图相结合的功能。它不是pretty的,而且我们也不是很自信的在里面,只是还没有,但它暂时。

We already have a working prototype that hacks together the functionality we need using a combination of focus listeners and list views. It isn't pretty, and we aren't very confident in it just yet, but it works for the time being.

我们真的很喜欢的是在交流抛出所有的原型UI code离开使用内置的TabWidget。然而,由于TabWidget很难coded到只能与最上面的标签的工作方式,这是不是一个真正的选择。

What we'd really like is to throw all of our prototype UI code away in exchange for using the built in TabWidget. However, since TabWidget is hardcoded to only work with the tabs on top, this isn't really an option.

所以,我们希望有人在那里有一个补丁或补丁集,或者自定义类,即处理TabWidget功能与侧面呢?

So, we are hoping that someone out there has a patch, or set of patches, or perhaps a custom class, that handles the TabWidget functionality with the tabs on the side instead?

相关code为TabWidget是在这里:http://www.google.com/$c$csearch/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

The relevant code for the TabWidget is here: 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

和具体的功能是很难codeD为是在顶部的标签是

and the specific function that is hardcoded for being tabs on top is

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

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

If anyone has any information, I'd be much obliged.

推荐答案

(请注意,我添加了一个更好的回答进一步下跌,过去就行了。我要离开这其中最突出的情况下,它更适合别人的需要。)

(Note that I added a better answer further down, past the line. I'm leaving this top one in in case it better fits someone else's needs.)

是啊,我一直在处理同样的问题。我有一个有点笨拙的解决方案。我注意到,你可以旋转pretty的多用任何浏览setRotate。不幸的是,这只旋转的形象,或什么的,并没有完全解决的问题或位置或大小或对齐。即便如此,我已经成功地凑齐东西还挺补偿它,虽然它只是完成了一半(完全不是那么回事的权利,如果你旋转为纵向)。下面被称为每当片旋转或布局被重新安排或什么的。

Yeah, I've been dealing with the same issue. I have a somewhat clunky solution. I noticed that you can rotate pretty much any View with setRotate. Unfortunately, this only rotates its image, or something, and doesn't fully deal with issues or placement or size or alignment. Even so, I've managed to cobble together something that kinda compensates for it, though it's only half done (doesn't quite work right if you rotate to portrait orientation). The following gets called whenever the tablet is rotated or the layout gets rearranged or whatever.

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包含MAINVIEW包含myTabHost包含LL1;你必须初始化code赋予它们的方式。的想法是,TabHost被顺时针旋转,并且它的尺寸必须手动换,使得它的容器知道它是一个不同的尺寸/形状,现在,否则边缘得到切断。此外,它的一些计算完成,以便它围绕得到正确的点旋转时​​,或至少在正确的位置结束。结果并不总是有意义,所以我只是改变的东西,直到它的工作,至少在横向模式。在TabHost的内容得到旋转,也因此有code在那里旋转回​​来,至少在第一个标签,这是LL1。其他标签需要被旋转回类似。我搞砸周围的这一段时间,并且可能有一些东西是不必要的。例如,MAINVIEW。我认为,这并不需要在那里。哦,并且如果TabHost是在不同的地方,则数字将需要以某种方式调整。祝你好运。无论如何,我希望这可以帮助别人。男人,Android的界面是如此加重......我希望他们能解决这个问题....我承认,虽然,尽管所有的障碍和挫折,任何组件旋转的是的pretty的清凉。我只是希望一切工作就像你所期望的。

llMain contains mainView contains myTabHost contains ll1; you'll need to have assigned them as such in the initialization code. The idea is that the TabHost gets rotated clockwise, and its dimensions have to be manually swapped so that its containers know that it's a different size/shape, now, otherwise the edges get cut off. Also, it some calculations are done so that it get rotated around the right point, or at least ends up in the right place. The results didn't always make sense, so I just changed stuff until it worked, at least in landscape mode. The contents of the TabHost get rotated, too, so there's code in there that rotates it back, at least the first tab, which is ll1. Other tabs would need to be rotated back similarly. I messed around with this for a while, and there may be some things that are unnecessary. For example, the mainView. I think that doesn't need to be there. Oh, and if the TabHost is in a different place, the numbers will need to be adjusted somehow. Good luck with that. Anyway, I hope this helps somebody. Man, Android GUI is so aggravating...I wish they'd fix it.... I'll admit, though, that despite all the obstacles and frustrations, rotation of any component is pretty cool. I just wish everything else worked like you'd expect.

嘿,我只是想出了如何得到它正确地做到这一点!标签留水平,这样就可能会或可能不会是一件好事,这取决于你想要什么,但无论如何:

Hey, I just figured out how to get it to do it properly! The labels stay horizontal, so that may or may not be a good thing, depending on what you want, but anyway:

<?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。只需添加在code选项卡;有很帖子周围的。复制/修改/做任何你需要做的,使之满足您的需求。此外,因为它很酷,我添加了周围的tabwidget滚动视图,所以它会自动允许滚动,如果你有太多的标签。它摆脱,如果你不想要它。得到了滚动的东西大多是从 http://java.dzone.com/articles/scrolling-tabs -Android 。耶!

This XML file defines an empty tabhost with the tabs on the right. Just add the tabs in your code; there're posts around for that. Copy/alter/do whatever you need to do to make it fit your needs. Also, because it's cool, I added a scroll view around the tabwidget, so it'll automatically allow scrolling if you have too many tabs. Get rid of it if you don't want it. Got the scroll thing mostly from http://java.dzone.com/articles/scrolling-tabs-android. Yay!