Android的滚动型,并在屏幕下方的按钮并在、按钮、屏幕、Android

2023-09-05 08:43:49 作者:爱意退朝.

我想实现这个:一个包含许多元素(ImageViews,TextViews,EditTexts等),滚动视图,然后滚动型后,一些按钮(这是自定义ImageViews)出现总是恰好在屏幕的底部。

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 ImageViews) that appear always exactly at the bottom of the screen.

如果我使用android:fillViewport =true属性,那么如果滚动型的元素是太大,以适应屏幕尺寸的按键让不可见的。如果我使用了android:体重= 1属性,然后滚动型只能得到50%的屏幕的时候,屏幕大,能适应(我想要的按钮在一个很小的比例,约10%)。如果我设置了android:重量以更大的值,则该按钮会出现非常小的。

If I use the android:fillViewport="true" attribute, then if the elements of the ScrollView are too big to fit in the screen size the buttons get invisible . If I use the android:Weight=1 attribute then the ScrollView gets only 50% of the Screen when the screen is big and it can fit (I want the buttons to take a small percentage, about 10%). If I set the android:Weight to bigger values then the buttons appear very small.

请帮忙!也许这是一些简单的,我忽略了,但我一直在敲打我的头几个小时!

Please help! Maybe it is something simple that I overlooked but I’ve been banging my head for hours!

推荐答案

创建并测试它。看起来你想要的。

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="fill_parent"
                android:layout_height="fill_parent">

    <LinearLayout
            android:id="@+id/buttons"
            android:layout_width="fill_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="fill_parent"
            android:layout_height="fill_parent"
            android:layout_above="@id/buttons">
         <!--Scrollable content here-->
        <LinearLayout
                android:layout_width="fill_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>