我正在玩 android 布局并尝试进行简单的 QA 测试,但我无法获得正确的布局。我只是不知道如何调整这些东西,经过几个小时的战斗,我几乎不需要帮助。
这是我想要的:
我得到的是:
这是我的 XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<RelativeLayout
android:id="@+id/nodeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textQuestion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="TextView"
android:textSize="18dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
<RadioGroup
android:id="@+id/radioAnswersGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</RadioGroup>
<LinearLayout
android:id="@+id/questionsNavigationGroup"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal" >
<Button
android:id="@+id/buttonPreviousQuestion"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_weight="1"
android:background="@drawable/fancy_button"
android:gravity="center|center_vertical"
android:onClick="onPreviousQuestionButtonClick"
android:shadowColor="#fff"
android:shadowRadius="3"
android:text="Back"
android:textColor="#432f11"
android:textSize="24dp" />
<Button
android:id="@+id/buttonNextQuestion"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_weight="1"
android:background="@drawable/fancy_button"
android:gravity="center|center_vertical"
android:onClick="onNextQuestionButtonClick"
android:shadowColor="#fff"
android:shadowRadius="3"
android:text="Next"
android:textColor="#432f11"
android:textSize="24dp" />
<Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</ScrollView>
</LinearLayout>
答案和按钮应始终位于底部,而问题应始终位于顶部。但是当文本很长时, View 应该在 ScrollView 内拉伸(stretch)。
我找到了没有相对布局的方式。我不知道这是错误还是功能,但此布局按我想要的方式缩放。
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textQuestion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="top" />
<LinearLayout
android:id="@+id/bottomStuff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="bottom"
android:orientation="vertical" >
<RadioGroup
android:id="@+id/radioAnswersGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</RadioGroup>
<LinearLayout
android:id="@+id/questionsNavigationGroup"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal" >
<Button
android:id="@+id/buttonPreviousQuestion"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_weight="1" />
<Button
android:id="@+id/buttonNextQuestion"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_weight="1" />
<Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
最佳答案
我认为你应该使用这个:
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true" >
关于Android RelativeLayout 对齐关注,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8542257/
假设您从ActiveSupport::Concern的文档中获得此代码,但您希望包含的Fooblock具有不同的内容,具体取决于包含Foo的模块或类。在我试图解决的特定问题中,我有一组地址验证,但地址字段将被命名为home_zip_code或work_zip_code,我希望包含验证问题以了解zip_code的前缀字段。require'active_support/concern'moduleFooextendActiveSupport::Concernincludeddo#havesome_valuebeaccessibledefself.method_injected_by_foo
介绍 最近在做微信小程序时,顶部标题栏总是与胶囊对不齐。往往是在这款手机上对齐了,在另外一款手机差很多。我在查阅资料后,提出了一种方法解决这个问题,即:在页面onLoad或组件created时,利用微信小程序提供的API,获取系统状态栏高度和胶囊信息,进而动态调整顶部标题栏样式。在苹果、小米、荣耀手机做验证,能做到精准对齐。理论 胶囊样式应该是垂直居中,有1px的border,border-radius为18px。 若要使顶部标题栏与胶囊对齐,则其高度必须是导航栏高度,标题栏内容也要垂直居中,顶部标题栏的外边距或内边距必须是状态栏高度。 如果顶部
我正在尝试将一些内容垂直居中放置在bounding_box中。对于单个文本,这没问题:bounding_box([0,bounds.top],:width=>pdf.bounds.right,:height=>pdf.bounds.top)dotext"verticallyalignedinthesurroundingbox",:valign=>:centerend但是如果我的边界框中有多个元素,我该怎么办:bounding_box([0,bounds.top],:width=>pdf.bounds.right,:height=>pdf.bounds.top)dotext"vertic
最近我正在构建一个复杂的逻辑Controller,由于“单一责任”原则,我想重构它。所以我阅读了有关服务的信息。但有时后来我看到了担忧。我认为它是ruby中服务的替代品(因为没有默认的服务文件夹等),但找不到任何像“关注与服务”之类的好文章。我听说关注的是Controller的模型和服务,但仍然找不到任何主题或文章来证明这一点。谁能解释一下服务和问题的区别以及何时使用它们? 最佳答案 关注点和服务是非常不同的抽象模式,用于完全不同的目的。服务是转化为类的操作/功能。关注的是mixins.假设我想对用户进行身份验证。我可以轻松地编
考虑到Rails,我可以通过包含它们来通过模块提供我的模型类方法和实例方法。不过,我发现没有任何博客条目或线程提到如何在我的模型中包含变量。具体来说,我想给我的包含模型一个类实例变量@question,但我不知道将声明放在模块中的什么地方,所以它会被应用。如果模型本身声明了该变量,我还希望重写类实例变量。ActiveSupport::Concern模块真的关心变量吗?moduleContentAttributeextendActiveSupport::Concerndeffoop"hi"endmoduleClassMethods#@question="Iamagenericquesti
我有一个名为User的ActiveRecord类。我正在尝试创建一个名为Restrictable的关注点,它接受如下一些参数:classUser然后我想提供一个名为restricted_data的实例方法,它可以对这些参数执行一些操作并返回一些数据。示例:user=User.find(1)user.restricted_data#Returnsallcolumnsexcept:id,:name,:email我该怎么做? 最佳答案 如果我正确理解你的问题,这是关于如何写这样一个问题,而不是关于restricted_data的实际返回值
假设我在ruby中有以下结构(没有rails)moduleParentdeffputs"inparent"endendmoduleChilddeffsuperputs"inchild"endendclassAincludeParentincludeChildendA.new.f#prints=>#inparent#inchild现在使用rails时的问题moduleParentextendActiveSupport::Concernincludeddodeffputs"InParent"endendendmoduleChildextendActiveSupport::Concern
场景我提取了一个名为Taggable的关注点。它是一个允许任何模型支持标记的模块。我已将此关注点/模块包含到模型中,例如User、Location、Places、Projects。我想为这个模块编写测试,但不知道从哪里开始。问题1。我可以对Taggable问题进行隔离测试吗?在下面的示例中,测试失败是因为测试正在查找dummy_class表。我假设它这样做是因为Taggable中的has_many代码,因此它期望'DummyClass'是一个ActiveRecord对象。#/app/models/concerns/taggable.rbmoduleTaggableextendActiv
我正在阅读一些使用Rails4中关注点的代码。我看了一些文章说,如果我们想包含类方法使用模块ClassMethods,但我阅读的代码使用类似:class_methodsdodef****endend 最佳答案 ActiveSupport::Concern为模块混合的常见Ruby模式提供语法糖。当您使用modulesasmixins时你不能像在类中那样只使用self来声明类方法:moduleFoodefself.bar"HelloWorld"enddefinstance_method"HelloWorld"endendclassBaz
我试图在我的应用程序中表示用户之间的关系,其中一个用户可以有很多关注者并且可以关注其他用户。我想要像user.followers()和user.followed_by()这样的东西你能详细告诉我如何使用ActiveRecord表示这个吗?谢谢。 最佳答案 你需要两个模型,一个Person和一个FollowingsrailsgeneratemodelPersonname:stringrailsgeneratemodelFollowingsperson_id:integerfollower_id:integerblocked:boole