有什么办法让Mvx.MvxLinearLayout尊重android:layout_weight吗?

有什么办法让Mvx.MvxLinearLayout尊重android:layout_weight吗?,第1张

概述我有一个水平的项目列表,希望平均共享可用的屏幕宽度.以前,我曾使用索引绑定到每个项目,并使用静态LinearLayout来使每个项目具有相同的layout_weight.当我用Mvx.MvxLinearLayout和ItemsSource绑定替换静态LinearLayout并将项目的标记移动到Itemtemplate中时,MvxLinearLayout不再

我有一个水平的项目列表,希望平均共享可用的屏幕宽度.

以前,我曾使用索引绑定到每个项目,并使用静态linearLayout来使每个项目具有相同的layout_weight.

当我用Mvx.MvxlinearLayout和ItemsSource绑定替换静态linearLayout并将项目的标记移动到Itemtemplate中时,MvxlinearLayout不再考虑layout_weight.

我尝试了各种方法来重组项目模板,并且似乎没有办法让此控件在安排其项目时服从layout_weight.

有没有什么方法可以让Mvx.MvxlinearLayout尊重android:layout_weight,或者有其他方法可以给我一个动态的项目列表,这些项目将在给定固定尺寸边界的情况下进行均匀排列?

编辑

假设包含3个项目的列表,其字符串属性为“名称”.

该标记可以正常工作,提供3个等宽的文本项:

<linearLayout    androID:orIEntation="horizontal"    androID:layout_wIDth="fill_parent"    androID:layout_height="wrap_content">    <TextVIEw        androID:layout_weight="1"        androID:layout_wIDth="0dp"        androID:layout_height="wrap_content"        local:MvxBind="Text Items[0].name"        />    <TextVIEw        androID:layout_weight="1"        androID:layout_wIDth="0dp"        androID:layout_height="wrap_content"        local:MvxBind="Text Items[1].name"        />    <TextVIEw        androID:layout_weight="1"        androID:layout_wIDth="0dp"        androID:layout_height="wrap_content"        local:MvxBind="Text Items[2].name"        /></linearLayout>

此方法不起作用,布局权重未正确应用于TextVIEw:

<Mvx.MvxlinearLayout    androID:orIEntation="horizontal"    androID:layout_wIDth="fill_parent"    androID:layout_height="wrap_content"    local:MvxBind="ItemsSource Items"    local:MvxItemTemplate="@layout/item_template" />

ItemTemplate布局文件:

<?xml version="1.0" enCoding="utf-8"?><TextVIEw xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:local="http://schemas.androID.com/apk/res-auto"    androID:layout_weight="1"    androID:layout_wIDth="0dp"    androID:layout_height="wrap_content"    local:MvxBind="Text name" />

解决方法:

问题是,将MvxlinearLayout与ItemTemplate一起使用时,mvvmcross会插入一个附加视图.因此,与其获取视图层次结构,不如:

MvxlinearLayout->文字检视

您最终得到:

MvxlinearLayout-> MvxListItemVIEw-> TextVIEw.

因此,适用于TextVIEw的布局属性(尤其是权重)对于linearLayout是不可见的. MvxListItemVIEw使用默认的布局属性(包装内容)填充,并且看不到任何重量效果.

动作发生的位置在MvxVIEwGroupExtensions(例如Refill)中,子视图添加到linearLayout中,在MvxAdapter中,CreateBindableVIEw方法,子视图打包在IMvxListItemVIEw中.

解决此问题的一种方法是覆盖MvxVIEwGroupExtensions中的方法,并在添加视图后更新MvxListItemVIEws的布局属性(例如,从基础视图复制它们).例如:

private static voID Refill(this VIEwGroup vIEwGroup, IAdapter adapter) {    .... // rest of code    InvalIDate();    for (int j = 0; j < vIEwGroup.ChildCount; j++)    {        var child = GetChildAt(j) as MvxListItemVIEw;        var param = new linearLayout.LayoutParams(                     0, VIEwGroup.LayoutParams.WrapContent, 1.0f);        child.LayoutParameters = param;    }}
总结

以上是内存溢出为你收集整理的有什么办法让Mvx.MvxLinearLayout尊重android:layout_weight吗?全部内容,希望文章能够帮你解决有什么办法让Mvx.MvxLinearLayout尊重android:layout_weight吗?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1076548.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存