これに対する「類似した」質問と回答が散在しているようです。これらはすべて、からカスタム属性を取得する方法を示していますAttributeSet
。これまで私が見つけられなかったのは、android:
名前空間タグを取得する方法です。
<com.custom.view.StatusThumbnail
android:id="@+id/statusThumbnailContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"/>
layout_height
このカスタムコンポーネントから属性をプルバックしたいと思います。残念ながら、私がこれを行う方法に最も近いものを読んだことから、次のようになります。
public StatusThumbnail(Context context, AttributeSet attrs) {
super(context, attrs);
String height = attrs.getAttributeValue("android", "layout_height");
しかし、これはを返しますnull
。
確かに、これは珍しいことではありませんか?