我的简单android应用程序不断崩溃
我有一个简单的android应用程序,当我启动它时,它会不断崩溃。模拟器说appname一直在停止。我没有编辑活动类中的默认代码。我的布局xml如下所示:我的简单android应用程序不断崩溃,android,android-layout,Android,Android Layout,我有一个简单的android应用程序,当我启动它时,它会不断崩溃。模拟器说appname一直在停止。我没有编辑活动类中的默认代码。我的布局xml如下所示: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" androi
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/lblName"
android:text="Name"
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<EditText
android:id="@+id/txtName"
android:layout_alignParentLeft="true"
android:layout_below="@id/lblName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
/>
<LinearLayout
android:layout_alignParentLeft="true"
android:layout_below="@id/txtName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="@+id/btnSubmit"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Submit"
></Button>
<Button
android:id="@+id/btnCancel"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Cancel"
></Button>
</LinearLayout>
</RelativeLayout>
LinearLayout内的按钮应具有属性android:layout_width=0dp我已修复了您的布局,在LinearLayout上添加android:weightSum=1,在button上添加宽度为0 dp
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/lblName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="Name" />
<EditText
android:id="@+id/txtName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/lblName"
android:inputType="text" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/txtName"
android:orientation="horizontal"
android:weightSum="1">
<Button
android:id="@+id/btnSubmit"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:text="Submit" />
<Button
android:id="@+id/btnCancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:text="Cancel" />
</LinearLayout>
同时发布此活动的java代码:Post yout logcat或您获取的错误Post stacktrace至少向我们显示日志错误和活动code@admireChikudo,你忘了给按钮加上版面宽度。将android:layout\u width=wrap\u内容设置为布局中使用的每个按钮。