Android ScrollView and buttons at bottom of the screen

前端 未结 5 1117
广开言路
广开言路 2020-12-04 15:51

I want to implement this: A ScrollView that contains many elements (ImageViews, TextViews, EditTexts etc) and then after the ScrollView some buttons (which are custom ImageV

相关标签:
5条回答
  • 2020-12-04 16:01

    If you do not want to use RelativeLayout, it is better to use LinearLayout. This method is better in my opinion.

    Just set the layout_weight to one

    0 讨论(0)
  • 2020-12-04 16:12

    This worked for me. Give the scroll view a weight of 1. Put all the other widgets following the scroll view in a layout. The scroll view will grow enough to not block the rest.

    Widgets in scroll view and rest at bottom

    0 讨论(0)
  • 2020-12-04 16:16

    Just created and tested it. Looks like you want.

    <?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">
    
        <LinearLayout
                android:id="@+id/buttons"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:gravity="center"
                android:layout_alignParentBottom="true">
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Custom Button1"/>
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Custom Button2"/>
        </LinearLayout>
    
        <ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@id/buttons">
             <!--Scrollable content here-->
            <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">                
                <TextView
                        android:layout_height="wrap_content"
                        android:layout_width="wrap_content"
                        android:text="test text"
                        android:textSize="40dp"/>
            </LinearLayout>
        </ScrollView>
    
    </RelativeLayout>
    
    0 讨论(0)
  • 2020-12-04 16:16
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">
                <TextView 
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="Hello World"
                />
                <TextView 
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="Hallo Welt"
                />       
            </LinearLayout>
        </ScrollView>
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0">
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Go next page"
                android:layout_alignParentRight="true" />
        </RelativeLayout>
    
    </LinearLayout>
    
    0 讨论(0)
  • 2020-12-04 16:24

    scrollview cannot fit the screen because you put it on a linear layout, so linear layout fit in the screen,

    just try to make scrollview as root elemen on xml layout

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    
        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
            <!-- Here you can put some XML stuff and BOOM! your screen fit to scrollview -->
    
        </LinearLayout>
    </ScrollView>
    
    0 讨论(0)
提交回复
热议问题