【问题标题】:Code for EditText box underneath the ScrollView?ScrollView 下方的 EditText 框的代码?
【发布时间】:2013-04-15 17:27:23
【问题描述】:

嗨,我想把我的 EditText 框放在我的 ScrollView 上方,这样用户仍然可以向下滚动,但同时仍然可以在顶部的固定视图中看到 EditText 我该怎么做? //

这是我的代码

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    tools:context=".BitActivity" >

<EditText
                android:id="@+id/input"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"
                android:layout_alignParentTop="true"
                android:ems="10"
                android:gravity="center"
                android:hint="Type In Your Value"
                android:inputType="numberDecimal"
                android:textColor="#2FB3E3"
                android:textSize="30px" >
                <requestFocus />
            </EditText>

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent" >



            <TextView
                android:id="@+id/byte1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"
                android:layout_below="@+id/input"
                android:gravity="center"
                android:text="Please Enter a Value"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:textColor="#FFFF00"
                android:textSize="40px" />

        </RelativeLayout>
    </ScrollView>

</RelativeLayout>

【问题讨论】:

  • 哇,你这么快就对我的回答投了反对票,很抱歉没有提供它这是我尝试过的,但它只是与 textview 重叠

标签: android eclipse android-edittext android-scrollview


【解决方案1】:

在您的ScrollView 中有android:layout_alignParentTop="true"。但是ScrollViews 的父级是RelativeLayout,这意味着它将ScrollView 的顶部与RelativeLayout 的顶部(即屏幕顶部)对齐。

尝试用这个替换你当前的ScrollView::

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_below="@id/input"
>

这里的关键是这一行:android:layout_below="@id/input",它将ScrollViews 的顶部与View 的底部对齐,id 为“input”的底部。

【讨论】:

  • 我只是有点卡在如何开始我不应该做某种类型的Relativelayout并且编辑文本在那里并且滚动文本来保存我的长文本吗?
  • @user2283550 不确定您的意思。您想要文本上方的 EditText 吗?以及EditText下方可滚动视图中的文本?那么当你滚动 EditText 时,它会停留在屏幕的顶部吗?
  • 是的,你说得对,我上面说的我应该做什么,或者我应该尝试别的什么?
  • @user2283550 保留您当前的代码,除非您将 ScrollView 替换为我发布的代码。它应该强制 EditText 下方的 ScrollView
  • 抱歉回复晚了,谢谢你的朋友,你没有意识到有 android:layout_below="@id/mything" 用于滚动视图安全! :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多