Android relativelayout使我的按钮停止工作
当我使用linearlayout时,除了我的按钮在屏幕的顶部而不是底部之外,所有的东西都像它想象的那样工作 当我使用relativelayout时,我的按钮位于底部,就像它应该的那样,但仅适用于第一个listview条目,之后它停止工作Android relativelayout使我的按钮停止工作,android,xml,Android,Xml,当我使用linearlayout时,除了我的按钮在屏幕的顶部而不是底部之外,所有的东西都像它想象的那样工作 当我使用relativelayout时,我的按钮位于底部,就像它应该的那样,但仅适用于第一个listview条目,之后它停止工作 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button android:id="@+id/plus"
android:background="@drawable/selector"
android:layout_width="fill_parent"
android:layout_height="75dp"
android:layout_alignParentBottom="true"
/>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</ListView>
<TextView android:id="@android:id/empty" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/helptxt1"
/>
</RelativeLayout>
按钮不起作用,因为当您使用相对布局时,所有视图/按钮都放置在同一位置,除非您将它们放置在彼此的上方或下方。尝试在布局中执行此操作:
<Button
android:id="@+id/plus"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/plus" >
</ListView>
我不确定你能做到这一点。列表视图可以无限扩展,不能放在滚动视图中。因此,您可能无法在列表视图下设置按钮。
<Button
android:id="@+id/plus"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/plus" >
</ListView>
<Button
android:id="@+id/plus"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:onClick="myClickMethod" />
public void myClickMethod(View view) {
createNote();
}