简体   繁体   中英

How can I put my button at the bottom of a ScrollView?

I am very new to Android programming and I'm still a little bit confused with the different layouts. I want to have a Heading "Spieler: "(Player) and a Scroll View where you can type in the player. Underneath a plus-button that is always underneath the last field (with java code you can add more player-fields when clicking the plus-button).

This is how it looks like: Preview

But the plus-button should be on the right side underneath "Spieler 2" field.

This is my xml code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
    android:id="@+id/Spieler"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Spieler: "
    android:textSize="14pt"
    android:layout_marginBottom="30dp"/>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true">
    <LinearLayout
        android:id="@+id/mlayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
<EditText
    android:id="@+id/eingabe1"
    android:layout_width="550px"
    android:layout_marginStart="40px"
    android:layout_height="wrap_content"
    android:hint="@string/Spieler1"
    android:inputType="textCapWords"
    android:singleLine="true" />
<EditText
    android:id="@+id/eingabe2"
    android:layout_width="550px"
    android:layout_marginStart="40px"
    android:layout_height="wrap_content"
    android:hint="@string/Spieler2"
    android:inputType="textCapWords"
    android:singleLine="true" />
    </LinearLayout>
</ScrollView>
</LinearLayout>
<ImageButton
    android:id="@+id/plus"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:layout_gravity="right"
    android:layout_marginRight="20dp"
    android:background="@drawable/button_plus"/>
</RelativeLayout>

I found a very similar question here: How can I fix a button at the bottom in the scrollview android? And I changed my code a bit but I cant make it work :(

Thanks for any help!

Just try this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myLinear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
 >
<TextView
    android:id="@+id/Spieler"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Spieler: "
    android:textSize="14pt"
    android:layout_marginBottom="30dp"/>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true">
    <LinearLayout
        android:id="@+id/mlayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
<EditText
    android:id="@+id/eingabe1"
    android:layout_width="550px"
    android:layout_marginStart="40px"
    android:layout_height="wrap_content"
    android:hint="@string/Spieler1"
    android:inputType="textCapWords"
    android:singleLine="true" />
<EditText
    android:id="@+id/eingabe2"
    android:layout_width="550px"
    android:layout_marginStart="40px"
    android:layout_height="wrap_content"
    android:hint="@string/Spieler2"
    android:inputType="textCapWords"
    android:singleLine="true" />
    </LinearLayout>
</ScrollView>
</LinearLayout>
<ImageButton
    android:id="@+id/plus"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:layout_gravity="right"
    android:layout_marginRight="20dp"
    android:layout_below="@id/myLinear"
    android:background="@drawable/button_plus"/>
</RelativeLayout>

This solve your problem. :)

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