新手,第二天学Android了,看着例子准备仿照着写一个通讯录
但是在做UI的时候遇到个问题,实在不明白是哪里出了问题?难道是两个LinearLayout不能紧挨着写吗?
写了两个LinearLayout,结果就跑不起来了!
代码如下:
- XML code
<?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" android:orientation="vertical" > <ScrollView android:id="@+id/ScollView1" android:layout_weight="4" android:layout_width="fill_parent" android:layout_height="wrap_content" android:scrollbars="vertical"> <!-- 姓名 --> <LinearLayout android:id="@+id/widget205" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:layout_marginRight="20dp"> <ImageButton android:id="@+id/image_button" android:layout_width="60dip" android:layout_height="60dip" android:src="@drawable/contact" android:scaleType="centerCrop"/> <EditText android:id="@+id/username" android:layout_width="fill_parent" android:layout_height="wrap_content" android:scrollbars="vertical" android:hint="@string/addnew_uname" android:gravity="top" android:layout_gravity="center_vertical"/> </LinearLayout> <!-- 单位名称 【把下面的这个LinearLayout删了就能跑起来】--> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_marginLeft="10dp" android:layout_marginRight="10dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="单位:" android:textSize="20dp"/> <EditText android:id="@+id/company" android:layout_width="fill_parent" android:layout_height="wrap_content" android:scrollbars="vertical" android:gravity="top" android:hint="单位名称" android:phoneNumber="true"/> </LinearLayout> </ScrollView></LinearLayout>
------解决方案--------------------
你是不能运行,还是看不到你想要的结果?最好是把logcat贴出来,可能是页面布局问题!
------解决方案--------------------
Caused by: java.lang.IllegalStateException: ScrollView can host only one direct child
这句~~ ScrollView 只能有一个下级