我在android xml布局中遇到了一个问题

时间:2015-02-23 17:48:03

标签: android xml layout

这是我的布局

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


    <ProgressBar
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/progress_save_veterinaria"
        android:visibility="invisible"
        android:layout_gravity="center_horizontal|center_vertical"/>


    <LinearLayout
        android:id="@+id/lay_titulo"
        android:clickable="false"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:baselineAligned="false">

        <ScrollView
            android:id="@+id/container_scroll_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >
            <LinearLayout
                android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="10dp">


                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:background="@android:drawable/btn_default">


                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.95"

                        android:text="@string/nueva_veterinaria_titulo"
                        android:textSize="20sp" />

                    <ImageView
                        android:layout_width="40dp"
                        android:layout_height="40dp"
                        android:id="@+id/imageView"
                        android:background="@drawable/ic_nuevamascota" />
                </LinearLayout>



                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent">

                    <TextView
                        android:text="@string/veterinaria_nombre_title"

                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.25" />

                    <EditText
                        android:id="@+id/txt_veterinaria_nombre"

                        android:ems="8"

                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.75"
                        android:inputType="none" />
                </LinearLayout>

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent" >

                    <TextView
                        android:text="@string/veterinaria_dueno_title"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.25" />

                    <EditText
                        android:id="@+id/txt_veterinaria_dueno"
                        android:hint=""
                        android:ems="8"
                        android:inputType="textPersonName"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.75" />
                </LinearLayout>

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent" >

                    <TextView
                        android:text="@string/veterinaria_direccion_title"

                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.25" />

                    <EditText
                        android:id="@+id/txt_veterinaria_direccion"
                        android:hint=""
                        android:ems="8"

                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.75" />
                </LinearLayout>

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent" >

                    <TextView
                        android:text="@string/veterinaria_ciudad_title"

                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.25" />

                    <EditText
                        android:id="@+id/txt_veterinaria_ciudad"

                        android:hint=""
                        android:ems="8"

                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.75" />
                </LinearLayout>

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent" >

                    <TextView
                        android:text="@string/veterinaria_provincia_title"

                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.25" />

                    <EditText
                        android:id="@+id/txt_veterinaria_provincia"
                        android:hint=""
                        android:ems="8"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.75" />
                </LinearLayout>

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent" >

                    <TextView
                        android:text="@string/veterinaria_pais_title"

                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.25" />

                    <Spinner
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:id="@+id/spi_veterinaria_pais"

                        android:ems="8"
                        android:spinnerMode="dropdown"
                        android:layout_weight="0.75" />
                </LinearLayout>

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_marginBottom="5dp"
                    android:layout_marginTop="5dp">

                    <TextView
                        android:text="@string/veterinaria_servicios_title"

                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.25" />

                    <com.example.chronos7.mascotasegura.MultiSelectionSpinner
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:id="@+id/spi_veterinaria_servicios"

                        android:spinnerMode="dropdown"
                        android:layout_weight="0.75" />
                </LinearLayout>

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_marginTop="5dp"
                    android:layout_marginBottom="5dp">

                    <TextView
                        android:text="@string/veterinaria_productos_title"

                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.25" />

                    <com.example.chronos7.mascotasegura.MultiSelectionSpinner
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:id="@+id/spi_veterinaria_productos"
                        android:spinnerMode="dropdown"
                        android:layout_weight="0.75" />
                </LinearLayout>

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content">

                    <TextView
                        android:text="@string/veterinaria_adomicilio_title"

                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.25" />

                    <CheckBox
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:text=""
                        android:id="@+id/chk_adomicilio"


                        android:layout_weight="0.75"
                        android:layout_gravity="center" />
                </LinearLayout>

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent">

                    <TextView
                        android:text="@string/veterinaria_idioma_title"

                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.25" />

                    <EditText
                        android:id="@+id/txt_veterinaria_idioma"
                        android:hint=""
                        android:ems="8"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.75" />
                </LinearLayout>

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent">

                    <TextView
                        android:text="@string/veterinaria_horario_title"

                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.25" />

                    <EditText
                        android:id="@+id/txt_veterinaria_horario"
                        android:hint=""
                        android:ems="8"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.75" />
                </LinearLayout>

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent">

                    <TextView
                        android:text="@string/veterinaria_telefono_title"

                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.25" />

                    <EditText
                        android:id="@+id/txt_veterinaria_telefono"
                        android:hint=""
                        android:ems="8"
                        android:inputType="phone"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.75" />
                </LinearLayout>

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent">

                    <TextView
                        android:text="@string/veterinaria_celular_title"

                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.25" />

                    <EditText
                        android:id="@+id/txt_veterinaria_celular"
                        android:hint=""
                        android:ems="8"
                        android:inputType="phone"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.75" />
                </LinearLayout>

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent">

                    <TextView
                        android:text="@string/veterinaria_email_title"

                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.25" />

                    <EditText
                        android:id="@+id/txt_veterinaria_email"
                        android:inputType="textEmailAddress"
                        android:hint=""
                        android:ems="8"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.75" />
                </LinearLayout>

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent">

                    <TextView
                        android:text="@string/veterinaria_website_title"

                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.25" />

                    <EditText
                        android:id="@+id/txt_veterinaria_website"
                        android:inputType="textWebEditText"
                        android:hint=""
                        android:ems="8"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.75" />
                </LinearLayout>


                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">


                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"


                        android:text="@string/veterinaria_logo_title"
                        android:layout_weight="0.25" />

                    **<Button
                        android:id="@+id/btn_veterinaria_photo"

                        android:layout_height="wrap_content"

                        android:text="@string/veterinaria_logo_button"

                        android:onClick="veterinaria_dialog_photo"

                        android:layout_width="0dp"
                        android:layout_weight="0.75" />**

                </LinearLayout>



                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent">

                    <TextView
                        android:text="@string/veterinaria_imagen_title"

                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.25" />

                    <ImageView
                        android:layout_width="0dp"
                        android:layout_height="100dp"
                        android:id="@+id/img_veterinaria"

                        android:layout_weight="0.75" />
                </LinearLayout>


                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal" >

                    <View
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.25" />

                    <LinearLayout
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.75"
                        android:orientation="horizontal"
                        android:gravity="right">


                        <ImageButton
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"

                            android:id="@+id/btn_veterinaria_cancelar"
                            android:background="@drawable/ic_cancel_button"
                            android:onClick="veterinaria_cancelar"
                            />

                        <ImageButton
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"

                            android:id="@+id/btn_veterinaria_guardar"

                            android:background="@drawable/ic_save_button"
                            android:onClick="grabar_veterinaria"/>


                    </LinearLayout>
                </LinearLayout>

            </LinearLayout>



        </ScrollView>


    </LinearLayout>




</FrameLayout>

我在android studio预览中获取了nullPointerException,如果我删除名为&#34的按钮; btn_veterinaria_photo&#34;布局显示没有问题。

我正在使用android studio 1.1

我,我坚持了几天......任何帮助都将非常感激

我在android预览中得到了这个:

java.lang.NullPointerException
    at android.view.ViewGroup_Delegate.drawShadow(ViewGroup_Delegate.java:74)
    at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3404)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
    at android.view.View.draw(View.java:15017)
    at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3404)
    at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:53)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3404)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
    at android.view.View.draw(View.java:15017)
    at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3404)
    at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:53)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3404)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
    at android.view.View.draw(View.java:15117)
    at android.widget.FrameLayout.draw(FrameLayout.java:592)
    at android.widget.ScrollView.draw(ScrollView.java:1689)
    at android.view.View.draw(View.java:15022)
    at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3404)
    at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:53)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3404)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
    at android.view.View.draw(View.java:15017)
    at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3404)
    at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:53)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3404)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
    at android.view.View.draw(View.java:15017)
    at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3404)
    at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:53)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3404)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
    at android.view.View.draw(View.java:15017)
    at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3404)
    at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:53)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3404)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
    at android.view.View.draw(View.java:15117)
    at android.view.View.draw(View.java:15022)
    at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3404)
    at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:53)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3404)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
    at android.view.View.draw(View.java:15117)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.render(RenderSessionImpl.java:587)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:334)
    at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350)
    at com.android.tools.idea.rendering.RenderService$5.compute(RenderService.java:708)
    at com.android.tools.idea.rendering.RenderService$5.compute(RenderService.java:697)
    at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:932)
    at com.android.tools.idea.rendering.RenderService.createRenderSession(RenderService.java:697)
    at com.android.tools.idea.rendering.RenderService.render(RenderService.java:816)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.doRender(AndroidLayoutPreviewToolWindowManager.java:646)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.access$1700(AndroidLayoutPreviewToolWindowManager.java:82)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7$1.run(AndroidLayoutPreviewToolWindowManager.java:589)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl$2.run(ProgressManagerImpl.java:178)
    at com.intellij.openapi.progress.ProgressManager.executeProcessUnderProgress(ProgressManager.java:209)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:212)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:171)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7.run(AndroidLayoutPreviewToolWindowManager.java:584)
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320)
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310)
    at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.java:254)
    at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269)
    at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227)
    at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217)
    at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
    at com.intellij.util.Alarm$Request$1.run(Alarm.java:327)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:744)

***当我在真实手机上测试时,布局正确显示。

0 个答案:

没有答案