Android 4.01 冰淇淋三明治 Galaxy Nexus 上 Tabactivty 中 ListView 中的 EditText 小部件

发布于 2024-12-29 15:37:04 字数 8361 浏览 1 评论 0原文

已解决:

我已经解决了我的问题。为了获得所需的功能,我做了其他事情。事实证明,scrollView 中有一个 tabHost 是问题所在,但据我测试,这只是 Android 4.0+ 的问题。下面的代码使我能够“缩小”我的选项卡小部件,从而使我的应用程序能够“全屏”。我希望有一天这会对某人有所帮助 xD。

public class MyScaler extends ScaleAnimation
{
    private View         mView;

    private LayoutParams mLayoutParams;

    private int          mMarginBottomFromY, mMarginBottomToY;

    private boolean      mVanishAfter = false;

    public MyScaler(float fromX, float toX, float fromY, float toY, int duration, View view, boolean vanishAfter)
    {
        super(fromX, toX, fromY, toY);
        setDuration(duration);
        mView = view;
        mVanishAfter = vanishAfter;
        mLayoutParams = (LayoutParams) view.getLayoutParams();
        final int height = mView.getHeight();

        if(fromY > toY)
        {
            mMarginBottomFromY = (int) (height * fromY) + mLayoutParams.bottomMargin - height;
            mMarginBottomToY = (int) (0 - ((height * toY) + mLayoutParams.bottomMargin)) - height;

        }
        else
        {
            mMarginBottomFromY = mLayoutParams.bottomMargin;
            mMarginBottomToY = 0;
            mView.setVisibility(View.VISIBLE);
        }

    }

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t)
    {
        super.applyTransformation(interpolatedTime, t);

        if (interpolatedTime < 1.0f)
        {
            int newMarginBottom = mMarginBottomFromY + (int) ((mMarginBottomToY - mMarginBottomFromY) * interpolatedTime);
            mLayoutParams.setMargins(mLayoutParams.leftMargin, mLayoutParams.topMargin, mLayoutParams.rightMargin, newMarginBottom);
            mView.getParent().requestLayout();
        }
        else if (mVanishAfter)
        {
            mView.setVisibility(View.GONE);
        }
        else if(!mVanishAfter)
        {
            mLayoutParams.setMargins(mLayoutParams.leftMargin, mLayoutParams.topMargin, mLayoutParams.rightMargin, 0);
            mView.getParent().requestLayout();
        }

    }



}

大家好 :) 我已经使用 Android/iOS 工作了一年多一点,并且作为业余爱好我已经使用 C/C++ 大约 5 年了。这段代码也是一个业余爱好项目。

我有一个相当具体的问题...我目前正在 Galaxy Nexus 上开发我的应用程序,开箱即用 Android 4.01 我也在 4.02 上对此进行了测试 - 相同。

我的问题是:

我在使用 BaseAdapter 子类的列表视图中的 LineayLayouts 中有几个 edittext 视图。每当我双击或“长按”此视图并且它包含文本时,我的应用程序就会崩溃并抛出 IllegalStateException。请参阅下面的调用堆栈。通常这会(在 Android 4.0+ 中,我猜是 3.2+)创建一个具有不同复制/粘贴选项的选项栏。

我的应用程序由一个带有 4 个选项卡的 Tabactivity 组成。这些选项卡是通过 4 个“子活动”制作的。我的 Tabhost 被滚动视图包围,以便我能够“全屏”并删除 tabwidget,但我认为这不是问题。我的问题存在于所有 4 个选项卡中。

以上所有内容均可在其他 4 种设备上完美运行,包括:HTC Desire、Samsung Galaxy S 2、HTC Hero 以及运行 2.3.3 的模拟器。 (我无法在我的 i7 1.6 四核上运行 4.0 模拟器,因为它只会使用 1/8 的处理能力)

但是,当我在弹出窗口(如 AlertDialog)中有 Edittext-view 时,双击/长按标记文本的功能运行得很好,并且屏幕顶部的新 4.0 栏会弹出,其中包含剪切、复制和粘贴等选项,并且运行得很好。

我尝试自己和在网上搜索解决方案,但找不到任何信息。我发现人们以前在使用 edittext 和 Listviews 时遇到过问题。我尝试将我的 Edittext 视图放在 LinearLayouts 中的一个巨大的 LinearLayout 而不是 Listview 中,但这没有任何区别。

任何意见将不胜感激!如果您需要更多信息,请告诉我! :) 谢谢:)

编辑:

我做了更多的研究,我尝试构建一个具有完全相同布局但没有围绕我的 tabhost 的滚动视图的应用程序。这有效。但并不能解决我的问题,除非我想重写大部分布局。

这是

<my.pack.MyScrollView xmlns:android="http://schemas.android.com/apk/res/android">          

    <LinearLayout android:orientation="vertical" android:id="@+id/ScrollLayout"
        android:layout_width="match_parent" android:layout_height="wrap_content">

        <TabHost 
            android:id="@android:id/tabhost"   android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout android:orientation="vertical"
                android:layout_width="match_parent" android:layout_height="wrap_content">

                <HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
                    android:id="@+id/tabs" android:layout_width="fill_parent"
                    android:layout_height="wrap_content" android:padding="0px"
                    android:layout_margin="0px" android:background="@drawable/horizontaltabbackground">

                    <TabWidget android:id="@android:id/tabs"
                        android:layout_width="fill_parent" android:layout_height="wrap_content"
                        android:padding="0px" android:layout_margin="0px" />

                </HorizontalScrollView>

                <FrameLayout android:id="@android:id/tabcontent"
                    android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#ff000000"/>

            </LinearLayout>

        </TabHost>

    </LinearLayout>

</my.pack.MyScrollView>

来自 Eclipse 的 Main.xml 调用堆栈:

Thread [<1> main] (Suspended (exception IllegalStateException)) 
    ActionBarContextView.onMeasure(int, int) line: 328  
    ActionBarContextView(View).measure(int, int) line: 12603    
    LinearLayout(ViewGroup).measureChildWithMargins(View, int, int, int, int) line: 4677    
    LinearLayout.measureChildBeforeLayout(View, int, int, int, int, int) line: 1369 
    LinearLayout.measureVertical(int, int) line: 660    
    LinearLayout.onMeasure(int, int) line: 553  
    LinearLayout(View).measure(int, int) line: 12603    
    PhoneWindow$DecorView(ViewGroup).measureChildWithMargins(View, int, int, int, int) line: 4677   
    PhoneWindow$DecorView(FrameLayout).onMeasure(int, int) line: 293    
    PhoneWindow$DecorView.onMeasure(int, int) line: 2072    
    PhoneWindow$DecorView(View).measure(int, int) line: 12603   
    FrameLayout(ViewGroup).measureChildWithMargins(View, int, int, int, int) line: 4677 
    FrameLayout.onMeasure(int, int) line: 293   
    FrameLayout(View).measure(int, int) line: 12603 
    LinearLayout(ViewGroup).measureChildWithMargins(View, int, int, int, int) line: 4677    
    LinearLayout.measureChildBeforeLayout(View, int, int, int, int, int) line: 1369 
    LinearLayout.measureVertical(int, int) line: 660    
    LinearLayout.onMeasure(int, int) line: 553  
    LinearLayout(View).measure(int, int) line: 12603    
    TabHost(ViewGroup).measureChildWithMargins(View, int, int, int, int) line: 4677 
    TabHost(FrameLayout).onMeasure(int, int) line: 293  
    TabHost(View).measure(int, int) line: 12603 
    LinearLayout(ViewGroup).measureChildWithMargins(View, int, int, int, int) line: 4677    
    LinearLayout.measureChildBeforeLayout(View, int, int, int, int, int) line: 1369 
    LinearLayout.measureVertical(int, int) line: 660    
    LinearLayout.onMeasure(int, int) line: 553  
    LinearLayout(View).measure(int, int) line: 12603    
    MyScrollView(ScrollView).measureChildWithMargins(View, int, int, int, int) line: 1163   
    MyScrollView(FrameLayout).onMeasure(int, int) line: 293 
    MyScrollView(ScrollView).onMeasure(int, int) line: 312  
    MyScrollView(View).measure(int, int) line: 12603    
    FrameLayout(ViewGroup).measureChildWithMargins(View, int, int, int, int) line: 4677 
    FrameLayout.onMeasure(int, int) line: 293   
    FrameLayout(View).measure(int, int) line: 12603 
    LinearLayout(ViewGroup).measureChildWithMargins(View, int, int, int, int) line: 4677    
    LinearLayout.measureChildBeforeLayout(View, int, int, int, int, int) line: 1369 
    LinearLayout.measureVertical(int, int) line: 660    
    LinearLayout.onMeasure(int, int) line: 553  
    LinearLayout(View).measure(int, int) line: 12603    
    PhoneWindow$DecorView(ViewGroup).measureChildWithMargins(View, int, int, int, int) line: 4677   
    PhoneWindow$DecorView(FrameLayout).onMeasure(int, int) line: 293    
    PhoneWindow$DecorView.onMeasure(int, int) line: 2072    
    PhoneWindow$DecorView(View).measure(int, int) line: 12603   
    ViewRootImpl.performTraversals() line: 1044 
    ViewRootImpl.handleMessage(Message) line: 2418  
    ViewRootImpl(Handler).dispatchMessage(Message) line: 99 
    Looper.loop() line: 137 
    ActivityThread.main(String[]) line: 4340    
    Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
    Method.invoke(Object, Object...) line: 511  
    ZygoteInit$MethodAndArgsCaller.run() line: 784  
    ZygoteInit.main(String[]) line: 551 
    NativeStart.main(String[]) line: not available [native method]  

SOLVED:

I have solved my problem. I've done something else in order to get the desired functionality. It turns out that having a tabHost in a scrollView was the problem, but its only a problem for Android 4.0+ as far as i have tested. The code below enables me to "shrink" my tabwidget which enables my app to go "fullscreen". I hope that this will some day help some one xD.

public class MyScaler extends ScaleAnimation
{
    private View         mView;

    private LayoutParams mLayoutParams;

    private int          mMarginBottomFromY, mMarginBottomToY;

    private boolean      mVanishAfter = false;

    public MyScaler(float fromX, float toX, float fromY, float toY, int duration, View view, boolean vanishAfter)
    {
        super(fromX, toX, fromY, toY);
        setDuration(duration);
        mView = view;
        mVanishAfter = vanishAfter;
        mLayoutParams = (LayoutParams) view.getLayoutParams();
        final int height = mView.getHeight();

        if(fromY > toY)
        {
            mMarginBottomFromY = (int) (height * fromY) + mLayoutParams.bottomMargin - height;
            mMarginBottomToY = (int) (0 - ((height * toY) + mLayoutParams.bottomMargin)) - height;

        }
        else
        {
            mMarginBottomFromY = mLayoutParams.bottomMargin;
            mMarginBottomToY = 0;
            mView.setVisibility(View.VISIBLE);
        }

    }

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t)
    {
        super.applyTransformation(interpolatedTime, t);

        if (interpolatedTime < 1.0f)
        {
            int newMarginBottom = mMarginBottomFromY + (int) ((mMarginBottomToY - mMarginBottomFromY) * interpolatedTime);
            mLayoutParams.setMargins(mLayoutParams.leftMargin, mLayoutParams.topMargin, mLayoutParams.rightMargin, newMarginBottom);
            mView.getParent().requestLayout();
        }
        else if (mVanishAfter)
        {
            mView.setVisibility(View.GONE);
        }
        else if(!mVanishAfter)
        {
            mLayoutParams.setMargins(mLayoutParams.leftMargin, mLayoutParams.topMargin, mLayoutParams.rightMargin, 0);
            mView.getParent().requestLayout();
        }

    }



}

Hi all :) I’ve worked with Android/iOS for a little more than a year and I have done C/C++ for about 5 as a hobby. This code in question is also a hobby project.

I have a fairly specific question... I'm currently developing my app on a Galaxy Nexus Running out of the box Android 4.01 i've also tested this on 4.02 - same.

My problem is:

I have several edittext views in LineayLayouts in a listview using a subclass of a BaseAdapter. Whenever i double click or "longclick" this view and it contains text my app crashes and throws an IllegalStateException. See call stack below.. Normally this would (in Android 4.0+ and I’m guessing 3.2+) create an option bar with different copy/paste options.

My App consists of a Tabactivity with 4 tabs. These tabs are made through 4 "child activities". My Tabhost is surrounded by a scrollview in order to make my able to go "fullscreen" and remove the tabwidget, but i don't think that’s the problem. My problem exists in all the 4 tabs.

All of the above works perfectly on 4 other devices, including: HTC Desire, Samsung Galaxy S 2, HTC Hero, and an emulator running 2.3.3. (I can't run the 4.0 emulator on my i7 1.6 quad because it will only use 1/8 of the processing power)

However when I have an Edittext-view in a pop-up like a AlertDialog then the double click / long click functionality in order to mark text works just fine, and the new 4.0 bar in the top of the screen with options like cut, copy, and paste pops up and works just fine.

I've tried to search for a solution myself and on the web but I’ve been unable to find any info. I've found that people have experienced problems with edittext and Listviews before. And I’ve tried putting my Edittext views in LinearLayouts in one huge LinearLayout instead of the Listview but this didn't make any difference.

Any input would be greatly appreciated! Please tell me if you need more info! :)
Thx :)

Edit:

I've done some more research and i've tried to build an app with the exact same layout but without the scrollview surrounding my tabhost. This works. But does not solve my problem unless i want to rewrite most of my layout.

This is my Main.xml

<my.pack.MyScrollView xmlns:android="http://schemas.android.com/apk/res/android">          

    <LinearLayout android:orientation="vertical" android:id="@+id/ScrollLayout"
        android:layout_width="match_parent" android:layout_height="wrap_content">

        <TabHost 
            android:id="@android:id/tabhost"   android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout android:orientation="vertical"
                android:layout_width="match_parent" android:layout_height="wrap_content">

                <HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
                    android:id="@+id/tabs" android:layout_width="fill_parent"
                    android:layout_height="wrap_content" android:padding="0px"
                    android:layout_margin="0px" android:background="@drawable/horizontaltabbackground">

                    <TabWidget android:id="@android:id/tabs"
                        android:layout_width="fill_parent" android:layout_height="wrap_content"
                        android:padding="0px" android:layout_margin="0px" />

                </HorizontalScrollView>

                <FrameLayout android:id="@android:id/tabcontent"
                    android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#ff000000"/>

            </LinearLayout>

        </TabHost>

    </LinearLayout>

</my.pack.MyScrollView>

Call stack from Eclipse:

Thread [<1> main] (Suspended (exception IllegalStateException)) 
    ActionBarContextView.onMeasure(int, int) line: 328  
    ActionBarContextView(View).measure(int, int) line: 12603    
    LinearLayout(ViewGroup).measureChildWithMargins(View, int, int, int, int) line: 4677    
    LinearLayout.measureChildBeforeLayout(View, int, int, int, int, int) line: 1369 
    LinearLayout.measureVertical(int, int) line: 660    
    LinearLayout.onMeasure(int, int) line: 553  
    LinearLayout(View).measure(int, int) line: 12603    
    PhoneWindow$DecorView(ViewGroup).measureChildWithMargins(View, int, int, int, int) line: 4677   
    PhoneWindow$DecorView(FrameLayout).onMeasure(int, int) line: 293    
    PhoneWindow$DecorView.onMeasure(int, int) line: 2072    
    PhoneWindow$DecorView(View).measure(int, int) line: 12603   
    FrameLayout(ViewGroup).measureChildWithMargins(View, int, int, int, int) line: 4677 
    FrameLayout.onMeasure(int, int) line: 293   
    FrameLayout(View).measure(int, int) line: 12603 
    LinearLayout(ViewGroup).measureChildWithMargins(View, int, int, int, int) line: 4677    
    LinearLayout.measureChildBeforeLayout(View, int, int, int, int, int) line: 1369 
    LinearLayout.measureVertical(int, int) line: 660    
    LinearLayout.onMeasure(int, int) line: 553  
    LinearLayout(View).measure(int, int) line: 12603    
    TabHost(ViewGroup).measureChildWithMargins(View, int, int, int, int) line: 4677 
    TabHost(FrameLayout).onMeasure(int, int) line: 293  
    TabHost(View).measure(int, int) line: 12603 
    LinearLayout(ViewGroup).measureChildWithMargins(View, int, int, int, int) line: 4677    
    LinearLayout.measureChildBeforeLayout(View, int, int, int, int, int) line: 1369 
    LinearLayout.measureVertical(int, int) line: 660    
    LinearLayout.onMeasure(int, int) line: 553  
    LinearLayout(View).measure(int, int) line: 12603    
    MyScrollView(ScrollView).measureChildWithMargins(View, int, int, int, int) line: 1163   
    MyScrollView(FrameLayout).onMeasure(int, int) line: 293 
    MyScrollView(ScrollView).onMeasure(int, int) line: 312  
    MyScrollView(View).measure(int, int) line: 12603    
    FrameLayout(ViewGroup).measureChildWithMargins(View, int, int, int, int) line: 4677 
    FrameLayout.onMeasure(int, int) line: 293   
    FrameLayout(View).measure(int, int) line: 12603 
    LinearLayout(ViewGroup).measureChildWithMargins(View, int, int, int, int) line: 4677    
    LinearLayout.measureChildBeforeLayout(View, int, int, int, int, int) line: 1369 
    LinearLayout.measureVertical(int, int) line: 660    
    LinearLayout.onMeasure(int, int) line: 553  
    LinearLayout(View).measure(int, int) line: 12603    
    PhoneWindow$DecorView(ViewGroup).measureChildWithMargins(View, int, int, int, int) line: 4677   
    PhoneWindow$DecorView(FrameLayout).onMeasure(int, int) line: 293    
    PhoneWindow$DecorView.onMeasure(int, int) line: 2072    
    PhoneWindow$DecorView(View).measure(int, int) line: 12603   
    ViewRootImpl.performTraversals() line: 1044 
    ViewRootImpl.handleMessage(Message) line: 2418  
    ViewRootImpl(Handler).dispatchMessage(Message) line: 99 
    Looper.loop() line: 137 
    ActivityThread.main(String[]) line: 4340    
    Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
    Method.invoke(Object, Object...) line: 511  
    ZygoteInit$MethodAndArgsCaller.run() line: 784  
    ZygoteInit.main(String[]) line: 551 
    NativeStart.main(String[]) line: not available [native method]  

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文