2013-01-16 94 views
0

我需要一個具有固定圖像和textview可滾動的佈局。問題是:如果文字增加,imageview變小,反之亦然。我想要修復圖像的大小。修復佈局imageview和可滾動textview

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:background="#000" 
     android:src="@drawable/luna" /> 

    <ScrollView 
     android:id="@+id/scrollView1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 

<TextView 
    android:text="test test test test" 
    android:textSize="15pt" 
    android:background="#000000" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1"/> 

</ScrollView> 
</LinearLayout> 

E/AndroidRuntime( 729): FATAL EXCEPTION: main 
E/AndroidRuntime( 729): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.luna/com.example.luna.MainActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class <unknown> 
E/AndroidRuntime( 729): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059) 
E/AndroidRuntime( 729): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 
E/AndroidRuntime( 729): at android.app.ActivityThread.access$600(ActivityThread.java:130) 
E/AndroidRuntime( 729): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 
E/AndroidRuntime( 729): at android.os.Handler.dispatchMessage(Handler.java:99) 
E/AndroidRuntime( 729): at android.os.Looper.loop(Looper.java:137) 
E/AndroidRuntime( 729): at android.app.ActivityThread.main(ActivityThread.java:4745) 
E/AndroidRuntime( 729): at java.lang.reflect.Method.invokeNative(Native Method) 
E/AndroidRuntime( 729): at java.lang.reflect.Method.invoke(Method.java:511) 
E/AndroidRuntime( 729): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
E/AndroidRuntime( 729): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
E/AndroidRuntime( 729): at dalvik.system.NativeStart.main(Native Method) 
E/AndroidRuntime( 729): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class <unknown> 
E/AndroidRuntime( 729): at android.view.LayoutInflater.createView(LayoutInflater.java:613) 
E/AndroidRuntime( 729): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 
E/AndroidRuntime( 729): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660) 
E/AndroidRuntime( 729): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685) 
E/AndroidRuntime( 729): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 
E/AndroidRuntime( 729): at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
E/AndroidRuntime( 729): at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
E/AndroidRuntime( 729): at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
E/AndroidRuntime( 729): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256) 
E/AndroidRuntime( 729): at android.app.Activity.setContentView(Activity.java:1867) 
E/AndroidRuntime( 729): at com.example.luna.MainActivity.onCreate(MainActivity.java:21) 
E/AndroidRuntime( 729): at android.app.Activity.performCreate(Activity.java:5008) 
E/AndroidRuntime( 729): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 
E/AndroidRuntime( 729): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023) 
E/AndroidRuntime( 729): ... 11 more 
E/AndroidRuntime( 729): Caused by: java.lang.reflect.InvocationTargetException 
E/AndroidRuntime( 729): at java.lang.reflect.Constructor.constructNative(Native Method) 
E/AndroidRuntime( 729): at java.lang.reflect.Constructor.newInstance(Constructor.java:417) 
E/AndroidRuntime( 729): at android.view.LayoutInflater.createView(LayoutInflater.java:587) 
E/AndroidRuntime( 729): ... 24 more 
E/AndroidRuntime( 729): Caused by: java.lang.OutOfMemoryError 
E/AndroidRuntime( 729): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) 
E/AndroidRuntime( 729): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:500) 
E/AndroidRuntime( 729): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:353) 
E/AndroidRuntime( 729): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:781) 
E/AndroidRuntime( 729): at android.content.res.Resources.loadDrawable(Resources.java:1930) 
E/AndroidRuntime( 729): at android.content.res.TypedArray.getDrawable(TypedArray.java:601) 
E/AndroidRuntime( 729): at android.widget.ImageView.<init>(ImageView.java:120) 
E/AndroidRuntime( 729): at android.widget.ImageView.<init>(ImageView.java:110) 
E/AndroidRuntime( 729): ... 27 more 
W/ActivityManager( 150): Force finishing activity com.example.luna/.MainActivity 
W/WindowManager( 150): Failure taking screenshot for (164x246) to layer 21010 
I/Choreographer( 150): Skipped 104 frames! The application may be doing too much work on its main thread. 
W/ActivityManager( 150): Activity pause timeout for ActivityRecord{412421f0 com.example.luna/.MainActivity} 
I/Choreographer( 150): Skipped 31 frames! The application may be doing too much work on its main thread. 
I/Choreographer( 262): Skipped 79 frames! The application may be doing too much work on its main thread. 
I/Choreographer( 150): Skipped 43 frames! The application may be doing too much work on its main thread. 
I/Choreographer( 150): Skipped 31 frames! The application may be doing too much work on its main thread. 
I/Choreographer( 150): Skipped 35 frames! The application may be doing too much work on its main thread. 
I/ActivityManager( 150): No longer want com.android.contacts (pid 371): hidden #16 
W/ActivityManager( 150): Activity destroy timeout for ActivityRecord{412421f0 com.example.luna/.MainActivity} 
+0

引起:java.lang.OutOfMemoryError現在問題不在您的佈局中。 – AMerle

回答

1

你嘗試android:layout_height="0dp"android:layout_weight="1"scrollview(並刪除它imageview/textview)?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/luna" /> 

    <ScrollView 
     android:id="@+id/scrollView1" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" > 

<TextView 
    android:text="test test test test" 
    android:textSize="15pt" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" /> 

</ScrollView> 
</LinearLayout> 
+0

謝謝。使用你的代碼我沒有看到任何文字。 –

+0

@PolHallen只是測試它,這很好。你在'imageview'和'textview'中刪除了'layout_weight'嗎? – AMerle

+0

無法啓動活動ComponentInfo {com.example.luna/com.example.luna.MainActivity}:android.view.InflateException:二進制XML文件行#8:錯誤膨脹類 E/AndroidRuntime(898):\t at android .app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) E/AndroidRuntime(898):\t at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) E/AndroidRuntime(898):\t at android.app .ActivityThread.access $ 600(ActivityThread.java:141) E/AndroidRuntime(898):\t at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1234) –