【问题标题】:Put something in the bottom part of a ScrollView在 ScrollView 的底部放一些东西
【发布时间】:2014-03-18 17:05:31
【问题描述】:

我有以下代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background_box">

    <ScrollView
        android:id="@+id/main_scroll"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true">

       [... center stuff]

    </ScrollView>

    <RelativeLayout
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:id="@+id/auth_non_auth_bottom"
        android:layout_below="@+id/main_scroll">
       [... buttons and stuff]
     </RelativeLayou>
</RelativeLayout>

在 Scrollview 里面有一个 EditText。由于 EditText 可以更改其高度,因此 Scrollview 可以越过 RelativeLayout 将其推到视图之外!

但是,如果我将 RelativeLayout 与 parentBottom 放在一起,它会在键入时隐藏编辑文本的键盘上方,因此用户无法编写......如果我将 RelativeLayout 放在滚动视图中......它不会位于视图的底部。

有什么想法可以实现将 RelativeLayout 置于底部但不隐藏 EditText(位于中心区域)的目标吗?谢谢!

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    我宁愿选择以下内容:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/background_box">
    
    <ScrollView
        android:id="@+id/main_scroll"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true">
       <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:gravity="center_horizontal">
          <EditText
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:lines="3"
            android:inputType="textMultiLine"
            android:id="@+id/description"
            android:clickable="true"/> 
          <RelativeLayout
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:id="@+id/auth_non_auth_bottom"
            android:layout_below="@+id/main_scroll">
           <!--[... buttons and stuff]-->
         </RelativeLayout>
       </LinearLayout>
    </ScrollView>
    </RelativeLayout>
    

    【讨论】:

    • 它不会走到底部 :(
    • 你能分享一个你想要实现的屏幕短片或图像吗?
    【解决方案2】:

    我做到了!这样:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/background_box">
    
        <ScrollView
            android:id="@+id/main_scroll"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_marginBottom="50dp">
    
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                >
                [...]
            </LinearLayout>
        </ScrollView>
    
        <RelativeLayout
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:id="@+id/auth_non_auth_bottom"
            android:layout_alignParentBottom="true"/>
    </RelativeLayout>
    

    我为 ScrollView 设置了一个 marginBottom 以便查看 editText 字段:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-09
      • 1970-01-01
      相关资源
      最近更新 更多