解决了:
我已经解决了我的问题。为了获得所需的功能,我做了其他事情。事实证明,在滚动视图中有一个 tabHost 是问题所在,但据我测试,这只是 Android 4.0+ 的问题。下面的代码使我能够“缩小”我的 tabwidget,从而使我的应用程序能够“全屏”运行。我希望有一天这会帮助一些人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 上工作了一年多一点,我做了大约 5 年的 C/C++ 作为业余爱好。这段代码也是一个爱好项目。
我有一个相当具体的问题......我目前正在 Galaxy Nexus 上开发我的应用程序,运行开箱即用的Android 4.01我也在 4.02 上测试过这个 - 相同。
我的问题是:
我在使用 BaseAdapter 的子类的列表视图中的 LineayLayouts 中有几个编辑文本视图。每当我双击或“长按”此视图并包含文本时,我的应用程序就会崩溃并引发 IllegalStateException。请参阅下面的调用堆栈。通常这会(在 Android 4.0+ 中,我猜是 3.2+ 中)创建一个具有不同复制/粘贴选项的选项栏。
我的应用程序包含一个带有 4 个选项卡的 Tabactivity。这些选项卡由 4 个“子活动”组成。我的 Tabhost 被滚动视图包围,以使我能够“全屏”并删除 tabwidget,但我认为这不是问题所在。我的问题存在于所有 4 个选项卡中。
以上所有功能都可以在其他 4 台设备上完美运行,包括:HTC Desire、三星 Galaxy S 2、HTC Hero 和运行 2.3.3 的模拟器。(我不能在我的 i7 1.6 quad 上运行 4.0 模拟器,因为它只会使用 1/8 的处理能力)
但是,当我在像 AlertDialog 这样的弹出窗口中有一个 Edittext-view 时,双击/长按功能以标记文本就可以正常工作,并且屏幕顶部的新 4.0 栏带有剪切、复制等选项,并且粘贴弹出并且工作正常。
我试图自己和在网上搜索解决方案,但我一直找不到任何信息。我发现人们以前在使用 edittext 和 Listviews 时遇到过问题。我已经尝试将我的 Edittext 视图放在 LinearLayouts 中,而不是 Listview 中的一个巨大的 LinearLayout 中,但这没有任何区别。
任何投入将不胜感激!如果您需要更多信息,请告诉我!:) 谢谢 :)
编辑:
我做了更多的研究,我尝试构建一个布局完全相同但没有围绕我的标签主机的滚动视图的应用程序。这行得通。但除非我想重写我的大部分布局,否则不能解决我的问题。
这是我的 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>
来自 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]