简体   繁体   English

android视图,解析xml文件时出错

[英]android view, error in parsing xml file

hi in my app i am trying to make an text view and edit box in a same line as if in iPhone apps. 嗨,在我的应用程序中,我试图像在iPhone应用程序中一样,在同一行中制作文本视图和编辑框。

after getting some info in the following link How can I implement this UI in Android , 在以下链接中获取一些信息后, 如何在Android中实现此用户界面

i created the two xml file. 我创建了两个xml文件。 the following is my main.xml file 以下是我的main.xml文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      android:background="@drawable/back"
      android:layout_marginRight="10dp"
      android:layout_marginBottom="10dp"
      android:layout_marginTop="20dp"
      xmlns:android="http://schemas.android.com/apk/res/android">
   <LinearLayout android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:orientation="horizontal"
                 android:paddingLeft="10dp">


      <TextView android:text="Initial"
                android:textColor="#686868"
                android:id="@+id/wideget02"
                android:textSize="10sp"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">
      </TextView>

      <EditText android:id="@+id/widget01"
                android:layout_width="fill_parent"
                android:layout_height="35dp"
                android:singleLine="true"
                android:inputType="textEmailAddress"
                android:textSize="15sp"
                android:background="@android:color/transparent" android:hint="Initial"/>
   </LinearLayout>

   <View android:layout_width="fill_parent" android:layout_height="1dip"
         android:background="#ababab"/>

   <LinearLayout android:layout_width="fill_parent"
                 android:layout_height="wrap_content" android:orientation="horizontal"
                 android:paddingLeft="10dp">
      <TextView android:text="Initial" android:textColor="#686868"
                android:id="@+id/widget02" android:textSize="10sp" android:layout_width="fill_parent"
                android:layout_height="wrap_content"
            ></TextView>

      <EditText android:id="@+id/widget01" android:layout_width="fill_parent"
                android:layout_height="35dp" android:singleLine="true"
                android:inputType="textEmailAddress" android:textSize="15sp"
                android:background="@android:color/transparent" android:hint="Initial"/>
   </LinearLayout>
</LinearLayout>

Following is the back.xml file which i have placed in drawable of resource folder 以下是我放置在资源文件夹的drawable中的back.xml文件

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

   <stroke android:width="1dp" android:color="#ababab"/>

   <padding android:left="1dp"
            android:top="1dp"
            android:right="1dp"
            android:bottom="1dp"
         />

   <corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp"
            android:topLeftRadius="7dp" android:topRightRadius="7dp"/>

</LinearLayout> 

When i run the app it shows the following errors in logcat 当我运行应用程序时,它在logcat中显示以下错误

03-24 11:51:40.191: ERROR/AndroidRuntime(638): Caused by: android.view.InflateException: Binary XML file line #3: Error inflating class java.lang.reflect.Constructor
03-24 11:51:40.191: ERROR/AndroidRuntime(638):     at android.view.LayoutInflater.createView(LayoutInflater.java:512)
03-24 11:51:40.191: ERROR/AndroidRuntime(638):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
03-24 11:51:40.191: ERROR/AndroidRuntime(638):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:562)
03-24 11:51:40.191: ERROR/AndroidRuntime(638):     at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
03-24 11:51:40.191: ERROR/AndroidRuntime(638):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
03-24 11:51:40.191: ERROR/AndroidRuntime(638):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
03-24 11:51:40.191: ERROR/AndroidRuntime(638):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:318)
03-24 11:51:40.191: ERROR/AndroidRuntime(638):     at android.app.Activity.setContentView(Activity.java:1631)
03-24 11:51:40.191: ERROR/AndroidRuntime(638):     at com.gis.ss.main.onCreate(main.java:16)
03-24 11:51:40.191: ERROR/AndroidRuntime(638):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1132)
03-24 11:51:40.191: ERROR/AndroidRuntime(638):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
03-24 11:51:40.191: ERROR/AndroidRuntime(638):     ... 11 more`

what it refers too, please explain me.. 它也代表什么,请给我解释一下。

The root element of your back drawable must not be a LinearLayout . back方可绘制对象的根元素不得为LinearLayout Looks like you need a shape there. 好像您需要在那里的shape

See this doc 看到这个文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM