我只是无法在屏幕底部显示按钮。我有 2 个 TextView 和 2 个编辑文本设置为消失,当用户单击复选框时它们变得可见。只有这样我的按钮才能正确定位否则它会在我的应用程序启动时位于应用程序的顶部。(参见此处:http://www.shrani.si/f/3V/10G/4nnH4DtV/layoutproblem.png) 我也试过 android:layout_alignParentBottom="true"但这也无济于事。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollview"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView android:id="@+id/txt1" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="Krajevna skupnost: "
android:layout_alignParentTop="true" />
<Spinner
android:id="@+id/spinner1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="@string/ks_prompt"
android:layout_below="@id/txt1"
/>
<TextView android:id="@+id/txt2" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="Zadeva: "
android:layout_below="@id/spinner1" />
<Spinner
android:id="@+id/spinner2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="@string/pod_prompt"
android:layout_below="@id/txt2"
/>
<TextView android:id="@+id/tv1" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="Zadeva: "
android:layout_below="@id/spinner2" />
<EditText android:id="@+id/prvi" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_below="@id/tv1" />
<TextView android:id="@+id/tv2" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_below="@id/prvi"
android:text="Vsebina: " />
<EditText android:id="@+id/drugi" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_below="@id/tv2" />
<CheckBox android:id="@+id/cek" android:text="Obveščaj o odgovoru"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_below="@id/drugi" />
<TextView android:id="@+id/tv3" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_below="@id/cek"
android:text="Email: "
android:visibility="gone"/>
<EditText android:id="@+id/tretji" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_below="@id/tv3"
android:visibility="gone" />
<TextView android:id="@+id/tv4" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_below="@id/tretji"
android:visibility="gone"
android:text="Telefon: " />
<EditText android:id="@+id/cetrti" android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_below="@id/tv4" />
<Button android:id="@+id/gumb"
android:text="Klikni"
android:typeface="serif" android:textStyle="bold"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_below="@id/cetrti" />
</RelativeLayout>
</ScrollView>
最佳答案
移除 ScrollView 并将 android:layout_alignParentBottom="true"设置为底部按钮。同时删除这一行:android:layout_below="@id/cetrti"。 如果你真的需要 ScrollView,你可以把它做成这样:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ScrollView
...
<RelativeLayout
...
</RelativeLayout>
</ScrollView>
<Button
android:layout_alignParentBottom="true"
...
</RelativeLayout>
关于java - Android相对布局问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2700583/