我正在尝试以编程方式将从 HTML 文件中选取的表单字段添加到 LinearLayout。我在底部有一个下一步按钮,但它在显示屏上一直被切断。我在平板电脑上试过了,但它仍然没有出现。
如您所见,元素正在渲染,但最后一个元素由于某种原因从屏幕上消失了。
fragment 的 XML:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".dataInput.PropertyInfoFragment"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:paddingLeft="20dp"
android:paddingRight="20dp">
<ScrollView
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linear_layout_property_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
<Button
android:id="@+id/nextButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/next"
android:background="@color/colorPrimary"
android:textColor="@android:color/white"/>
</LinearLayout>
</ScrollView>
</FrameLayout>
调用 Activity 的 XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".dataInput.DataInputActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_media_play" />
</android.support.design.widget.CoordinatorLayout>
我正在调用我在 fragment 的 onCreateView 中制作的方法 formInflator 并从 fragment 传递 LinearLayout 和一个 Elements 对象(来自Jsoup 库),其中包含我想放入 LinearLayout 中的所有元素:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
view = inflater.inflate(R.layout.fragment_property_info, container, false);
nextButton = (Button) view.findViewById(R.id.nextButton);
nextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onButtonPressed();
}
});
helpers.formInflator((LinearLayout) view.findViewById(R.id.linear_layout_property_info), generator.propertyTextElements);
return view;
}
这是方法 formInflator:
public void formInflator(LinearLayout parentLayout, Elements formElements) {
TextInputLayout index = null;
for(Element textField : formElements) {
TextInputEditText editText = new TextInputEditText(context);
editText.setId(View.generateViewId());
editText.setHint(textField.id());
editText.setText(textField.text());
LinearLayout.LayoutParams editTextParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
editText.setLayoutParams(editTextParams);
TextInputLayout textInputLayout = new TextInputLayout(context);
textInputLayout.setId(View.generateViewId());
textInputLayout.setTag(textField.id());
RelativeLayout.LayoutParams textInputLayoutParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
if (index == null)
index = textInputLayout;
else
textInputLayoutParams.addRule(RelativeLayout.BELOW, index.getId());
textInputLayout.setLayoutParams(textInputLayoutParams);
textInputLayout.addView(editText, editTextParams);
parentLayout.addView(textInputLayout, textInputLayoutParams);
index = textInputLayout;
}
}
知道我做错了什么吗?
最佳答案
试试嵌套 ScrollView 。它为我创造了奇迹。
<androidx.core.widget.NestedScrollView
-----
android:layout_width="match_parent"
android:layout_height="match_parent">
LinearLayout<
-----
</LinearLayout>
</androidx.core.widget.NestedScrollView>
关于Android ScrollView 在底部被截断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38663428/
我遇到了ruby正则表达式的问题。我需要找到所有(可能重叠的)匹配项。这是问题的简化:#Simpleexample"Hey".scan(/../)=>["He"]#Actualresults#Withoverlappingmatchestheresultshouldbe=>["He"],["ey"]我尝试执行并获得所有结果的正则表达式如下所示:"aaaaaa".scan(/^(..+)\1+$/)#Thislooksformultiplesof(here)"a"biggerthanonethat"fills"theentirestring."aa"*3=>true,"aaa"*2=
我有一个Rails应用程序。还有一个javascript(javascript1.js)文件必须包含在每个View的最底部。我把它放在/assets/javascripts文件夹中。Application.js包含以下代码//=requirejquery//=requirejquery_ujs//=someotherfiles//=require_directory.即使Application.js中不包含javascript1.js,它也会自动包含,不是吗?那么我怎样才能做我想做的事呢? 最佳答案 单独定义、包含和执行您的java
我使用的是ruby1.8.7。我可以发誓我之前已经在脚本底部编写了我的函数并且运行良好。我必须将它们放在顶部吗?这似乎是他们现在唯一的工作方式。没什么大不了的。我只是更喜欢将它们放在底部,所以我想我会问。 最佳答案 您可以在一个或多个BEGINblock中执行初始化代码(继承自Perl,后者继承自awk)。can_i_do_this?#=>yesBEGIN{defcan_i_do_this?puts"yes"end}为了完整起见,还有ENDblock:END{can_i_do_this?#=>yes}defcan_i_do_th
我有一个Rails站点,其中的内容是用markdown编写的。我希望显示每个片段,并带有“阅读更多..”链接。我该怎么做?简单截断原始文本将不起作用,例如..>>"Thisisan[example](http://example.com)"[0..25]=>"Thisisan[example](http:"理想情况下,我想让作者(可选)插入一个标记来指定要用作“片段”的内容,否则需要250个单词,并附加“...”-例如..Thisarticleisanexampleofsomethingorother.Thissegmentwillbeusedasthesnippetontheinde
我有两个字符串:short_string="helloworld"long_string="thisisaverylonglonglong....string"#supposemorethan10000chars我想将print的默认行为更改为:putsshort_string#=>"helloworld"putslong_string#=>"thisisaverylonglong....."long_string只打印了一部分。我尝试更改String#to_s,但没有成功。有谁知道如何做到这一点?已更新实际上我希望它能顺利运行,这意味着以下情况也能正常运行:>putsvery_lon
这是Mongoid记录操作的方式:D,[2016-01-12T18:42:19.790639#7906]DEBUG--:MONGODB|localhost:27017|app_test.update|STARTED|{"update"=>"users","updates"=>[{"q"=>{"_id"=>BSON::ObjectId('5695652bc54d2d1ee200001e')},"u"=>{"$addToSet"=>{"favorite_ids"=>{"$each"=>[BSON::ObjectId('5695652bc54d2d1ee200001f')]}}},"mult
有没有人手头有任何代码可以在RubyonRails中截断一个字符串?是这样的:例如:“HelloWorld,你好吗?”=>“喂……你?” 最佳答案 如果你想要一个固定的长度而不考虑字符串的长度,你可以使用Rails#truncate:s.truncate(100,omission:"...#{s.last(50)}") 关于ruby-on-rails-如何居中截断字符串?,我们在StackOverflow上找到一个类似的问题: https://stackove
我有一个float,我想截断到3个位置,但我不想四舍五入。例如,将1.0155555555555555转换为1.015(而不是1.016)。我将如何在Ruby中执行此操作? 最佳答案 您还可以转换为BigDecimal,然后对其调用truncate。1.237.to_d.truncate(2).to_f#willreturn1.23 关于ruby-截断float而不向上舍入,我们在StackOverflow上找到一个类似的问题: https://stackov
将字符串截断为前n个单词的最佳方法是什么? 最佳答案 n=3str="yourlonglonginputstringorwhatever"str.split[0...n].join('')=>"yourlonglong"str.split[0...n]#notethattherearethreedots,whichexcludesn=>["your","long","long"] 关于ruby-将字符串截断为前n个单词,我们在StackOverflow上找到一个类似的问题:
使用Rspec时截断、事务和删除数据库策略有什么区别?我找不到任何资源来解释这一点。我阅读了DatabaseCleaner自述文件,但它没有解释它们各自的作用。为什么我们必须对capybara使用截断策略?我是否必须在测试时清理我的数据库,或者我可以禁用它。我不明白为什么我应该在每个测试用例之后清理我的数据库,这不会减慢测试速度吗? 最佳答案 数据库清理策略引用数据库术语。IE。这些术语来自(SQL)数据库世界,因此通常熟悉数据库术语的人会知道它们的含义。以下示例引用了SQL定义。DatabaseCleaner也支持其他非SQL类型