0

我有这个非常简单的布局,2 个按钮,复选框,搜索栏和一些文本。它目前在 LinearLayout 上,我只能使用一半的屏幕,最多 5-6 行。我试图将按钮拖到按钮上,但我不能。就像他们被困在仅覆盖屏幕上半部分的框架中。任何建议如何解决这个问题?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/statusText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/timerText"
        android:layout_alignParentTop="true"
        android:layout_marginTop="31dp"
        android:text="@string/statusText"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <CheckBox
        android:id="@+id/timerCB"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/timerTime"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="44dp"
        android:onClick="activateTimer"
        android:text="@string/timerCB" />

    <Button
        android:id="@+id/stop_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="20dp"
        android:onClick="stopOperation"
        android:text="@string/stop_button" />

    <Button
        android:id="@+id/start_button"
        android:layout_width="319dp"
        android:layout_height="wrap_content"
        android:layout_above="@+id/stop_button"
        android:layout_alignParentRight="true"
        android:onClick="startOperation"
        android:text="@string/start_button" />

    <TextView
        android:id="@+id/timerText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/statusText"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="71dp"
        android:enabled="false"
        android:text="@string/timerText"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <SeekBar
        android:id="@+id/timerTime"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/timerText"
        android:layout_marginTop="32dp"
        android:enabled="false"
        android:max="90" />

</RelativeLayout>

我的日志是这样的:

02-09 17:01:41.107: E/AndroidRuntime(12469): FATAL EXCEPTION: main
02-09 17:01:41.107: E/AndroidRuntime(12469): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.remoteswitch/com.example.remoteswitch.MainActivity}: java.lang.ClassCastException: android.widget.Button cannot be cast to android.widget.CheckBox
02-09 17:01:41.107: E/AndroidRuntime(12469):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
02-09 17:01:41.107: E/AndroidRuntime(12469):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-09 17:01:41.107: E/AndroidRuntime(12469):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-09 17:01:41.107: E/AndroidRuntime(12469):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-09 17:01:41.107: E/AndroidRuntime(12469):    at android.os.Handler.dispatchMessage(Handler.java:99)
02-09 17:01:41.107: E/AndroidRuntime(12469):    at android.os.Looper.loop(Looper.java:137)
02-09 17:01:41.107: E/AndroidRuntime(12469):    at android.app.ActivityThread.main(ActivityThread.java:5039)
02-09 17:01:41.107: E/AndroidRuntime(12469):    at java.lang.reflect.Method.invokeNative(Native Method)
02-09 17:01:41.107: E/AndroidRuntime(12469):    at java.lang.reflect.Method.invoke(Method.java:511)
02-09 17:01:41.107: E/AndroidRuntime(12469):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-09 17:01:41.107: E/AndroidRuntime(12469):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-09 17:01:41.107: E/AndroidRuntime(12469):    at dalvik.system.NativeStart.main(Native Method)
02-09 17:01:41.107: E/AndroidRuntime(12469): Caused by: java.lang.ClassCastException: android.widget.Button cannot be cast to android.widget.CheckBox
02-09 17:01:41.107: E/AndroidRuntime(12469):    at com.example.remoteswitch.MainActivity.allocatePointers(MainActivity.java:60)
02-09 17:01:41.107: E/AndroidRuntime(12469):    at com.example.remoteswitch.MainActivity.onCreate(MainActivity.java:42)
02-09 17:01:41.107: E/AndroidRuntime(12469):    at android.app.Activity.performCreate(Activity.java:5104)
02-09 17:01:41.107: E/AndroidRuntime(12469):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-09 17:01:41.107: E/AndroidRuntime(12469):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
4

1 回答 1

0

对于外部 LinearLayout 你试过了吗

 android:layout_height="match_parent"

我也可以问你为什么选择

android:layout_height="0dp"

为您的小部件?是否有理由不使用“wrap_content”或非零值?

于 2013-02-09T16:43:15.977 回答