【问题标题】:Can I set a custom attribute on an android layout include tag?我可以在 android 布局包含标签上设置自定义属性吗?
【发布时间】:2012-07-18 06:18:42
【问题描述】:

我正在尝试在其根为自定义视图的布局的包含标记上设置自定义属性:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:archxs="http://schemas.android.com/apk/res/com.archxs.bincalc"
    android:id="@+id/calculatorRowMenuAnchor" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center_vertical"
    android:visibility="gone">

    <include android:id="@+id/calculatorrowmenu_result_running"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             archxs:isRunningResult="true"
             layout="@layout/single_line_result" />
...

包括:

<?xml version="1.0" encoding="utf-8"?>
<com.archxs.bincalc.SmallIntegerResultView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:orientation="horizontal"
    android:clickable="true">
...
</com.archxs.bincalc.SmallIntegerResultView>

但未设置自定义属性:

public SmallIntegerResultView(Context context, AttributeSet attrs) {
    super(context,attrs);
    final TypedArray styled = context.obtainStyledAttributes(attrs, R.styleable.ResultView);
    try {
        m_isRunningResult = styled.getBoolean(R.styleable.ResultView_isRunningResult, false);
    } finally {
        styled.recycle();
    }
}

这应该有效吗?如果不是为什么?如果是,我做错了什么?

谢谢大家?

【问题讨论】:

  • 而不是给布局中的高度宽度,包括给该布局中的父级(single_line_result)
  • 我也有同样的疑问。问题解决了吗?

标签: android xml android-layout android-xml


【解决方案1】:

对不起,可能有点晚了,但我遇到了类似的问题:

您是否在 attrs.xml 中声明了您的自定义属性?

查看此链接以获得更多解释:custom-xml-attributes-for-android-widgets

【讨论】:

  • 您的链接已失效 (404)
  • 对不起,已经很久了,我完全忘记了我是怎么做到的,我想这样做的方式也改变了
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-06-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-22
相关资源
最近更新 更多