简体   繁体   中英

Android relative layout problem

I just can't display the button at the bottom of the screen. I have 2 textviews and 2 edittexts set as gone, and they become visible when user clicks checkbox. It's only then that my button gets positioned properly Otherwise it sits on top of the app at launch of my app.(see here: http://www.shrani.si/f/3V/10G/4nnH4DtV/layoutproblem.png ) I also tried android:layout_alignParentBottom="true" but that doesnt help either.

 <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>

Remove ScrollView and set android:layout_alignParentBottom="true" to your bottom button. Also remove this line: android:layout_below="@id/cetrti". If you really need the ScrollView, you could make it something like this:

<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>

I ran it o 2.1 device - and it looked ok as it is . Button is positioned below checkbox. So i'm not sure what the problem is. As a quick fix that gonna work for sure - change relative layout to the LinearLayout. It little bit more expensive, but for your purpose IMO should work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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