- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我想延长我的 TableLayout
通过 ViewStab
的一些额外行元素。这是我的Activity
的布局:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/root_table_layout">
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Row 1"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Row 2"/>
</TableRow>
<ViewStub
android:id="@+id/view_stub_1"
android:layout="@layout/merge_table_1"/>
<ViewStub
android:id="@+id/view_stub_2"
android:layout="@layout/merge_table_2"/>
</TableLayout>
或者view_stub_1
或 view_stub_2
在 Activity
上膨胀onCreate
(这取决于应用程序的条件)。
ViewStub
应该膨胀用 <merge>
定义的布局标记为根元素。像这样:
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Row 5"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Row 6"/>
</TableRow>
</merge>
但是当Activity
正要开始,我得到了这个异常:
merge can be used only with a valid ViewGroup root and attachToRoot=true - worked with getLayoutInflater
最佳答案
好像<merge>
ViewStub
不支持标签现在的元素:
The only drawback of ViewStub is that it currently does not support the tag.
Romain Guy's post on layout tricks
最后我用了Activity
的 LayoutInflater
在 TableLayout
中包含其他行:
ViewGroup rootTableLayout = (ViewGroup) findViewById(R.id.root_table_layout);
getLayoutInflater().inflate(R.layout.merge_table_1, rootTableLayout, true);
因为我只想附上一些TableRows
在 ViewGroup
的和,此解决方案有效。对于更复杂的场景(在 TableRows
中间动态包含 TableLayout
),我仍然不知道什么是正确的方法。
关于android - 包含使用合并标签和 ViewStub 的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29344787/
我实现了这样的自定义 View : public class HeaderView extends LinearLayout { @Bind(R.id.bill_summary_layout)
我对 View stub 有疑问。 这是我java文件中的ViewStub ViewStub stub = (ViewStub) findViewById(R.id.stub1); ArrayAdap
我得到一个错误 07-04 01:49:56.325: E/AndroidRuntime(9693): java.lang.NullPointerException 同时尝试在交易完成后在 Fragm
这是我的用例: 我想在运行时更改我的膨胀布局,比如首先我膨胀布局 a,然后一段时间后我想显示布局 B,然后是布局 C,等等。 我在某处读到,与其在主布局中包含布局然后隐藏/取消隐藏,不如使用 view
LinearLayout 在 iflating ViewStub 后没有边距。充气后我只能通过编程方式设置边距还是有其他方法? 最佳答案 我遇到了同样的问题,但使用的是 RelativeLayout。
在我的应用程序中,我有一个微调器和一个 ViewStub,根据从微调器中选择的用户项目,我必须膨胀不同的布局并在微调器下方显示膨胀的布局。当我的应用程序启动时,ViewStub 会在第一次从微调器中选
我有一个 ListView,其中 listview 的每一行都包含大约 10 个 ImageButton。这些按钮中的大多数都具有可见性 = 消失并且仅在非常罕见的情况下出现。我想知道是否值得将这些
我想按语法在 View 组中定位一个 View stub 。 我尝试使用 setLayoutParams() 方法,但它不适用于 View stub 。 请提出任何解决方案。 下面是我的代码。 set
我正在尝试开发一个相当复杂的 appwidget,它可以通过编程方式更改它的一部分。 Android 建议这样的事情使用 ViewStub 小部件。 根据 AppWidgets page Remote
我正在研究您启动 Navigation Drawer Activity 时生成的示例代码。在 Android 工作室中。我想做的是以编程方式更改包含的 View ,我的研究表明 ViewStub 是做
我的布局上有一些 stub ,我想知道是否可以为它们设置动画,以便它们从一个滑到另一个。 非常感谢! 最佳答案 您可以使用 ViewFlipper 作为一个简单的解决方案。只需使用 ViewFlipp
我想将 ViewStub 添加到我的布局中。 ViewStub 应该是这样的,如 xml: 我已经想出了这段代码,但布局没有显示。 我正在重复使用 id,因为我要删除并再次添加 stub 。我猜代码
我有一个元素,里面有苹果、梨和柠檬。我为苹果、梨和柠檬做了单独的布局。 如果选择了任何元素,我想获取该元素的布局。我尝试根据使用 inflate() 函数选择的布局将正确的布局放入 viewStub。
我创建了一个使用 ViewStub 的库并将其集成到我的项目中。当我运行应用程序时,我得到 java.lang.IllegalArgumentException: ViewStub must have
我最近发现了一个名为 ViewStub 的类,它可用于“延迟加载”布局资源。用法非常简单: 在我使用的布局文件中: 在我的代码中: var stub = this.FindViewById(Reso
我没有发现任何 bool 方法可以完成这项任务。我可以通过检查 viewStub 的 id 是否更改为指定为 inflatedid 的那个来做到这一点吗? Java代码: protected
我是 Android 开发的新手。 我从 https://developer.android.com/training/improving-layouts/loading-ondemand.html
几天前,我遇到了新的 Twitter API(版本 3.1.1),我试图复制我在 tweets 列表中看到的效果。 不幸的是我是新用户,我不能发布图片,所以我试图解释我在说什么 有推文列表( List
膨胀包含 fragment 的 View stub 时是否有任何问题。在 crashalytics 中我很少看到 Fatal Exception: android.view.InflateExcept
我是安卓新手,我一直在做一个项目,在我的新闻提要页面中,我试图包含一个模块化的提要 RecyclerView,它显示一个具有不同答案形式的问题,根据问题类型而变化。到目前为止,我的做法是使用 incl
我是一名优秀的程序员,十分优秀!