草庐IT

android - 强制编辑文本在 ScrollView 中占据全屏

coder 2023-12-07 原文

我在 ScrollView 中的 LinearLayout 中有一个 EditText 字段。只要 ScrollView 不存在,layout_weight="1.0" 就会让我的 EditText 占据剩余的屏幕。但是,一旦我将 LinearLayout 包装在 ScrollView 中,它就会将 EditText 更改为单行,并且 layout_weight 不起作用。

我的完整布局文件

<LinearLayout   xmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="match_parent" android:layout_height="fill_parent"     android:orientation="vertical" >        

<TextView android:id="@+id/titleTextView"       
          style="@style/TitleHeaderBarText"     
          android:text="@string/announcement" />        

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" > 

    <LinearLayout  
         android:layout_width="match_parent" 
         android:layout_height="fill_parent"    
         android:orientation="vertical" 
         android:gravity="right" >

                <TextView 
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Subject:" 
                    android:textSize="16sp" />

                <EditText 
                    android:id="@+id/et_subject"
                    android:layout_width="match_parent" 
                    android:layout_height="wrap_content" />

               <TextView
                    android:layout_width="match_parent" 
                    android:layout_height="wrap_content"
                    android:text="Announcement:" 
                    android:textSize="16sp" />

                <EditText
                    android:id="@+id/et_announcement"
                    android:layout_width="match_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1.0" />

                <Button
                    android:id="@+id/btn_save"
                    android:layout_width="wrap_content" 
                    android:layout_height="wrap_content"
                    android:paddingLeft="24sp" 
                    android:paddingRight="24dp"
                    android:text="Save" />      

       </LinearLayout>  
</ScrollView>

</LinearLayout>

我似乎不明白我做错了什么。请就如何让 EditText 从 ScrollView 中的 LinearLayout 中占据屏幕的其余部分提出任何建议。

谢谢。

编辑 再次面临同样的问题,这是我的布局。

<?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" >

    <TextView android:id="@+id/titleTextView"
        style="@style/TitleHeaderBarText"
        android:text="@string/login_title" />

    <ScrollView
        android:id="@+id/sv_weight_tell_us"
        android:layout_width="match_parent" android:layout_height="match_parent"
        android:background="@drawable/bg_light_radial_pink" >
        <LinearLayout 
            android:layout_width="match_parent" android:layout_height="match_parent"
            android:padding="12dp"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/login_header"
                android:layout_width="match_parent" android:layout_height="wrap_content"
                android:text="Login" />

            <TableLayout 
                android:layout_width="match_parent" android:layout_height="wrap_content"
                android:stretchColumns="1" >
                <TableRow>
                    <TextView
                        android:layout_width="wrap_content" android:layout_height="wrap_content"
                        android:paddingRight="20dp"
                        android:text="@string/username" />
                    <EditText
                        android:id="@+id/et_username"
                        android:layout_width="wrap_content" android:layout_height="wrap_content" />
                </TableRow>
                <TableRow>
                    <TextView
                        android:layout_width="wrap_content" android:layout_height="wrap_content"
                        android:text="@string/password" />
                    <EditText
                        android:id="@+id/et_password"
                        android:layout_width="wrap_content" android:layout_height="wrap_content"
                        android:inputType="textPassword" />
                </TableRow>
                <TableRow>
                    <View/>
                    <Button
                        android:id="@+id/btn_login"
                        android:layout_width="wrap_content" android:layout_height="wrap_content"
                        android:text="@string/login"
                        android:padding="12dp" />
                </TableRow>
            </TableLayout>

            <ProgressBar
                android:id="@+id/pb_1"
                android:layout_width="wrap_content" android:layout_height="wrap_content"
                android:indeterminate="true"
                style="?android:attr/progressBarStyleSmall"
                android:visibility="invisible" />

            <TextView
                android:layout_width="wrap_content" android:layout_height="match_parent"
                android:layout_weight="1.0" android:gravity="bottom"
                android:text="@string/dont_have_Q" />           
            <TextView
                android:id="@+id/tv_sign_up"
                android:layout_width="wrap_content" android:layout_height="wrap_content"
                android:text="@string/sign_up_" />

        </LinearLayout>
    </ScrollView>

</LinearLayout>

最佳答案

需要添加ScrollView属性android:fillViewport="true":

...
<ScrollView
    android:id="@+id/sv_weight_tell_us"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:background="@drawable/bg_light_radial_pink"
    android:fillViewport="true" >
....

关于android - 强制编辑文本在 ScrollView 中占据全屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7047626/

有关android - 强制编辑文本在 ScrollView 中占据全屏的更多相关文章

  1. ruby - 使用 ruby​​ 将 HTML 转换为纯文本并维护结构/格式 - 2

    我想将html转换为纯文本。不过,我不想只删除标签,我想智能地保留尽可能多的格式。为插入换行符标签,检测段落并格式化它们等。输入非常简单,通常是格式良好的html(不是整个文档,只是一堆内容,通常没有anchor或图像)。我可以将几个正则表达式放在一起,让我达到80%,但我认为可能有一些现有的解决方案更智能。 最佳答案 首先,不要尝试为此使用正则表达式。很有可能你会想出一个脆弱/脆弱的解决方案,它会随着HTML的变化而崩溃,或者很难管理和维护。您可以使用Nokogiri快速解析HTML并提取文本:require'nokogiri'h

  2. ruby-on-rails - Rails 编辑表单不显示嵌套项 - 2

    我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib

  3. 安卓apk修改(Android反编译apk) - 2

    最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路

  4. ruby-on-rails - rspec - 我怎样才能让 "pendings"有我的文本而不仅仅是 "No reason given" - 2

    我有这个代码:context"Visitingtheusers#indexpage."dobefore(:each){visitusers_path}subject{page}pending('iii'){shouldhave_no_css('table#users')}pending{shouldhavecontent('Youhavereachedthispageduetoapermissionic错误')}它会导致几个待处理,例如ManagingUsersGivenapractitionerloggedin.Visitingtheusers#indexpage.#Noreason

  5. ruby - 如何为 pbcopy 生成富文本链接 - 2

    我一直在玩一个脚本,它在Chrome中获取选定的文本并在Google中查找它,提供四个最佳选择,然后粘贴相关链接。它以不同的格式粘贴,具体取决于当前在Chrome中打开的页面-DokuWiki打开的DokuWiki格式,普通网站的HTML,我想要我的WordPress所见即所得编辑器的富文本。我尝试使用pbpaste-Preferrtf来查看没有其他样式的富文本链接在粘贴板上的样子,但它仍然输出纯文本。在文本编辑中保存文件并进行试验后,我想出了以下内容text=%q|{\rtf1{\field{\*\fldinst{HYPERLINK"URL"}}{\fldrsltTEXT}}}|te

  6. ruby - 强制浏览器下载文件而不是打开文件 - 2

    我要下载http://foobar.com/song.mp3作为song.mp3,而不是让Chrome在其native中打开它浏览器中的播放器。我怎样才能做到这一点? 最佳答案 您只需要确保发送这些header:Content-Disposition:attachment;filename=song.mp3;Content-Type:application/octet-streamContent-Transfer-Encoding:binarysend_file方法为您完成:get'/:file'do|file|file=File.

  7. ruby-on-rails - 尝试打开 .gitignore 以在文本编辑器中对其进行编辑,但在 OS X Mountain Lion 上找不到文件位置 - 2

    我使用“newapp_name”创建了一个新的Rails应用程序,我正在尝试编辑.gitignore文件,但在我的应用程序文件夹中找不到它。我在哪里可以找到它?我安装了Git。 最佳答案 .gitignore位于项目的root中,而不是app子目录中。首先打开终端并进入您的目录。您需要使用ls-a来显示stash文件。然后使用打开.gitignore 关于ruby-on-rails-尝试打开.gitignore以在文本编辑器中对其进行编辑,但在OSXMountainLion上找不到文件位

  8. ruby - 如何将一段文本可逆地压缩成更少的 ASCII 字符? - 2

    我想获取任意的ASCII文本字符串,例如“Helloworld”,并将其压缩为字符数较少(尽可能少)的版本,但要采用可以解压缩的方式。压缩版本应仅由ascii字符组成。有没有一种方法可以做到这一点,尤其是在Ruby中? 最佳答案 如果知道只会使用ASCII字符,那就是每个字节的低7位。通过位操作,您可以将每8个字节混合成7个字节(节省12.5%)。如果您可以将其放入更小的范围(仅限64个有效字符),则可以删除另一个字节。但是,因为您希望压缩形式也只包含ASCII字符,所以会丢失一个字节-除非您的输入可以限制为64个字符(例如,有损压

  9. ruby-on-rails - ActiveRecord:除非另有说明,否则在保存之前使所有文本字段都调用 strip - 2

    多年来,我在各种网站上遇到过各种问题,用户在字符串和文本字段的开头/结尾放置空格。有时这些会导致格式/布局问题,有时会导致搜索问题(即搜索顺序看起来不对,但实际上并非如此),有时它们实际上会使应用程序崩溃。我认为这会很有用,而不是像我过去所做的那样放入一堆before_save回调,向ActiveRecord添加一些功能以在保存之前自动调用任何字符串/文本字段上的.strip,除非我告诉它不是,例如do_not_strip:field_x,:field_y或类定义顶部的类似内容。在我去弄清楚如何做到这一点之前,有没有人看到更好的解决方案?明确一点,我已经知道我可以做到这一点:befor

  10. ruby - 使用 Nokogiri 和 Ruby 从 html 文档获取链接和 href 文本? - 2

    我正在尝试使用nokogirigem提取页面上的所有url及其链接文本,并将链接文本和url存储在散列中。FooBar我想回去{"Foo"=>"#foo","Bar"=>"#bar"} 最佳答案 这是一个单行:Hash[doc.xpath('//a[@href]').map{|link|[link.text.strip,link["href"]]}]#=>{"Foo"=>"#foo","Bar"=>"#bar"}拆分一点可以说更具可读性:h={}doc.xpath('//a[@href]').eachdo|link|h[link.t

随机推荐