Get “android:layout_height” from `AttributeSet` in a custom view constructor
来源:互联网 发布:php msgpackunpack 编辑:程序博客网 时间:2024/05/22 08:14
Get “android:layout_height” from `AttributeSet` in a custom view constructor
up vote0down votefavorite
share [fb]share [tw]
There seems to be alot of "similar" questions and answers to this scattered around which all refer to how to get a custom attribute from an AttributeSet
. What I haven't been able to find so far is how to get an android namespace tag:
<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"/>
I would like to pull back the "layout_height" attribute from this custom component. Unfortunately from what I've read the closest I've got to how to do this is:
public StatusThumbnail(Context context, AttributeSet attrs) { super(context, attrs); String height = attrs.getAttributeValue("android", "layout_height");
But this returns null
.
Surely this isn't a rare thing to try and do?
android android-layout android-custom-view
97% accept rate
2 Answers
activeoldestvotes
up vote1down vote
The namespace should be "http://schemas.android.com/apk/res/android" android is an alias declared in your xml file
upvote flag
Genius. Fantastic - thanks very much. – Graeme 11 hours ago
- Get “android:layout_height” from `AttributeSet` in a custom view constructor
- Create a custom view in Android || 在 Android 中创建一个自定义 View
- Android: How to get a custom View's height and width? [duplicate]
- Creating a Custom View
- android自定义View_0——Create a custom view class
- Android custom view
- Android Custom View NullPointerException
- android custom view
- Android - Custom View
- android : custom view
- android in practice_Working with a custom ContentProvider(MyMoviesContentProvider)
- Creating custom View - Creating a View Class
- android AttributeSet
- Entity Framework: duplicate rows in resultset from a view
- Display a view from another controller in ASP.NET MVC
- Java Constructor From Thinking in Java C7
- android 之 custom view(一)
- Android Custom View (自定义 View)
- Java Annotation入门
- Android手机变砖后的自救方法
- JS日历控件
- 工程路径首字母大写导致tomcat工程无法访问的问题(工程在tomcat里面发布后,在应用列表里面可以看见,但是无法访问)
- 使用Android手机注意事项
- Get “android:layout_height” from `AttributeSet` in a custom view constructor
- 职场中必须知道的8条禁语
- 充电技巧 轻松待机48小时!
- 刷机风险揭秘
- ajax的XMLHttpRequest对象
- 乐phone新手十大实用技巧
- 活着不容易啊~
- 结构体成员的内存对齐
- 纠结的我