android:1.5中的ScrollView不起作用

时间:2011-05-17 11:52:27

标签: android scrollview

我的一个布局在1.6+上运行完美但在1.5上抛出错误并导致使用“强制关闭”关闭应用程序。布局包含RelativeLayout作为父级,ScrollView包含RelativeLayout作为子和imagevite,textview,edittext,子relativeleayout中的按钮。这是xml文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"  android:layout_height="fill_parent" 
  android:id="@+id/user_pswd_new_root" android:scrollbars="vertical" android:soundEffectsEnabled="true">

 <ScrollView android:id="@+id/ScrollViewLogin" android:layout_width="fill_parent" android:layout_height="wrap_content" android:scrollbarStyle="outsideInset" android:scrollbars="vertical" android:visibility="visible">
   <RelativeLayout android:layout_width="fill_parent" android:id="@+id/relativeLayout1" android:layout_height="fill_parent">

    <ImageView android:background="@drawable/logo_login_new" android:layout_height="wrap_content" android:id="@+id/imageView1" 
    android:layout_width="wrap_content" android:layout_alignParentLeft="true" android:layout_marginLeft="40dp"></ImageView>
    <TextView android:layout_height="wrap_content" android:textStyle="bold" 
    android:layout_width="wrap_content" android:text="@string/login_text" android:layout_marginRight="40dp" 
    android:textSize="25dp" android:id="@+id/textView1" android:layout_alignParentRight="true" android:layout_marginTop="20dp"></TextView>
    <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/imageView1" android:layout_margin="10dp" android:text="@string/username" android:id="@+id/textView2_usr" android:layout_marginTop="10dp"></TextView>
    <EditText android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_width="wrap_content" android:text="" android:layout_toRightOf="@+id/textView2_usr" android:layout_alignTop="@+id/textView2_usr" android:layout_marginRight="10dp" android:id="@+id/user_pwd_username"></EditText>
    <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentLeft="true" android:layout_marginLeft="10dp" android:layout_below="@+id/user_pwd_username" android:id="@+id/textView3_usr" android:text="@string/password"></TextView>
    <EditText android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_width="wrap_content" android:text="" android:layout_toRightOf="@+id/textView3_usr" android:layout_below="@+id/user_pwd_username" android:layout_marginRight="10dp" android:layout_alignLeft="@+id/user_pwd_username" android:id="@+id/user_pwd_password" android:password="true"></EditText>
    <CheckBox android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/user_pwd_password" android:text="@string/remMe" android:layout_marginLeft="10dp" android:id="@+id/user_pwd_remMeChk"></CheckBox>
    <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/user_pwd_remMeChk" android:text="@string/loginBtn" android:id="@+id/user_pwd_btn_ok" android:layout_marginLeft="40dp" android:width="100dp"></Button>
    <Button android:layout_height="wrap_content" android:id="@+id/user_pwd_btn_cancel" android:layout_alignParentRight="true" android:layout_width="wrap_content" android:layout_marginRight="40dp" android:layout_alignTop="@+id/user_pwd_btn_ok" android:text="@string/cancelBtn" android:width="100dp"></Button>
    <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Version" android:layout_alignParentRight="true" android:layout_below="@+id/user_pwd_btn_cancel" android:layout_marginRight="10dp" android:id="@+id/versionText" android:textSize="6dp"></TextView>
    <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="" android:layout_alignParentLeft="true" android:layout_below="@+id/versionText" android:layout_marginLeft="10dp" android:id="@+id/messageText" android:scrollbars="vertical"></TextView>

    </RelativeLayout>
 </ScrollView>        

</RelativeLayout>

我在LogCat中遇到的错误是:

05-17 17:07:02.110: ERROR/AndroidRuntime(1215): Uncaught handler: thread main exiting due to uncaught exception             
05-17 17:07:02.139: ERROR/AndroidRuntime(1215): java.lang.RuntimeException: Unable to start activity ComponentInfo{orange.android.vpn/orange.android.vpn.StartUltimate}: android.view.InflateException: Binary XML file line #11: Error inflating class java.lang.reflect.Constructor  
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2268)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at android.app.ActivityThread.access$1800(ActivityThread.java:112)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at android.os.Looper.loop(Looper.java:123)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at android.app.ActivityThread.main(ActivityThread.java:3948)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at java.lang.reflect.Method.invokeNative(Native Method)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at java.lang.reflect.Method.invoke(Method.java:521)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at dalvik.system.NativeStart.main(Native Method)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class java.lang.reflect.Constructor
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at android.view.LayoutInflater.createView(LayoutInflater.java:512)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:562)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:617)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:620)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:309)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at android.app.Dialog.setContentView(Dialog.java:400)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at orange.android.myw.LoginDialog.init(LoginDialog.java:78)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at orange.android.myw.LoginDialog.<init>(LoginDialog.java:72)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at orange.android.vpn.StartUltimate.onCreate(StartUltimate.java:129)
 05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
 05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     ... 11 more
05-17 17:07:02.139: ERROR/AndroidRuntime(1215): Caused by: java.lang.reflect.InvocationTargetException
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at android.widget.ImageView.<init>(ImageView.java:103)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at java.lang.reflect.Constructor.constructNative(Native Method)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at android.view.LayoutInflater.createView(LayoutInflater.java:499)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     ... 25 more
05-17 17:07:02.139: ERROR/AndroidRuntime(1215): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/scrollbar_handle_vertical.9.png from drawable resource ID #0x7f020005
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at android.content.res.Resources.loadDrawable(Resources.java:1641)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at android.content.res.TypedArray.getDrawable(TypedArray.java:548)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at android.view.View.<init>(View.java:1725)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at android.widget.ImageView.<init>(ImageView.java:107)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     ... 29 more
05-17 17:07:02.139: ERROR/AndroidRuntime(1215): Caused by: java.io.FileNotFoundException: res/drawable/scrollbar_handle_vertical.9.png
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at android.content.res.AssetManager.openNonAssetNative(Native Method)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at android.content.res.AssetManager.openNonAsset(AssetManager.java:392)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     at android.content.res.Resources.loadDrawable(Resources.java:1634)
05-17 17:07:02.139: ERROR/AndroidRuntime(1215):     ... 32 more

错误指向LoginDialog类中的setContentView()行。 谁能说出什么阻止它出现在1.5。

由于

2 个答案:

答案 0 :(得分:0)

第一个例外是FileNotFoundException。检查文件res/drawable/scrollbar_handle_vertical.9.png是否存在。

答案 1 :(得分:0)

解决方案:

错误所在的图像,即“0x7f020005”,这是一个.png图像。 1.5无法识别drawable-hdpi中的png图像或任何,它在/ drawable文件夹中查找。我在/ res中创建了一个可绘制的文件夹,并将png图像复制到它,屏幕显示出来。但是由于屏幕尺寸小,一切都是一个接一个。我在ScrollView中尝试使用android:scrollbars =“vertical | horizo​​ntal”属性,但它只能垂直滚动,水平滚动不起作用。现在怎么处理这个问题(滚动水平)?