如何让Android的自定义XML值?
-
25-09-2019 - |
题
我想发射的数量:在XML cellWidth:
<mobi.intuitit.android.p.launcher.CellLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:launcher="http://schemas.android.com/apk/res/mobi.intuitit.android.p.launcher"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
launcher:cellWidth="80dip"
/>
我知道,我可以得到它的自定义视图:
public CellLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CellLayout, defStyle, 0);
mCellWidth = a.getDimensionPixelSize(R.styleable.CellLayout_cellWidth, 100);
但我怎样才能得到它的活动?不是自定义视图。 谢谢!
解决方案
您的自定义视图应该从你的CellLayout.getCellWidth()
一个getter Activity
,并发现你可以得到它的价值了。
CellLayout cellLayout = (CellLayout)findViewById(R.id.cell_layout);
cellLayout.getCellWidth();
不隶属于 StackOverflow