Android ScrollView和屏幕底部的按钮

geo*_*rge 36 android scrollview android-layout

我想实现这个:ScrollView包含许多元素(ImageViews,TextViews,EditTexts等),然后在ScrollView之后的一些按钮(自定义ImageViews)总是出现在屏幕的底部.

如果我使用android:fillViewport ="true"属性,那么如果ScrollView的元素太大而不适合屏幕大小,那么按钮就会变得不可见.如果我使用android:Weight = 1属性,那么当屏幕很大并且它可以适合时,ScrollView只获得屏幕的50%(我希望按钮占用一小部分,大约10%).如果我将android:Weight设置为更大的值,那么按钮看起来非常小.

请帮忙!也许这是我忽略的简单事情,但我已经敲了几个小时!

Ale*_*sny 85

刚刚创建并测试了它.看起来像你想要的.

<?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>
Run Code Online (Sandbox Code Playgroud)


mac*_*Jun 11

<?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>
Run Code Online (Sandbox Code Playgroud)