【问题标题】:Assign percentage to PercentFrameLayout with databinding使用数据绑定将百分比分配给 PercentFrameLayout
【发布时间】:2016-03-10 16:23:50
【问题描述】:

尝试使用百分比支持库创建带有布局的简单图形,但我无法弄清楚如何通过数据绑定分配百分比来查看。尝试返回 String "60%", float 0.6f, Float 0.6f, int 60。没有任何效果。

 <View
   android:id="@+id/graph_before"
   android:layout_height="@dimen/list_graph_line_height"
   android:layout_gravity="center_vertical"
   android:background="@color/colorAccent"
   app:layout_marginLeftPercent="@{item.percentValueLeft}"
   app:layout_widthPercent="@{item.percentValueWidth}"
   />

【问题讨论】:

    标签: android android-databinding android-percent-library percent-support-library


    【解决方案1】:

    这样做的方法是在数据绑定和 PercentLayoutInfo 中使用自定义设置器:

    @BindingAdapter("app:layout_widthPercent")
    public static void setWidthPercent(View view, float width) {
        PercentLayoutHelper.PercentLayoutParams params =(PercentLayoutHelper.PercentLayoutParams) view.getLayoutParams();
        PercentLayoutHelper.PercentLayoutInfo info = params.getPercentLayoutInfo();
        info.weightPercent = width;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多