修复布局imageview和可滚动的textview

时间:2013-01-16 15:39:34

标签: android

我需要一个具有固定图像和可滚动文本视图的布局。问题是:如果文本增加,imageview变小,反之亦然。我想要修复图像大小。

<?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}

1 个答案:

答案 0 :(得分:2)

您是否在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>