문제

I want to get the number of launcher:cellWidth in xml:

<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"
/>

I know that I can get it in a Custom view by:

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);

But how Can I get it in a Activity? not a Custom view. Thanks!

도움이 되었습니까?

해결책

Your custom view should have a getter CellLayout.getCellWidth() and from your Activity, after finding you can get its value.

CellLayout cellLayout = (CellLayout)findViewById(R.id.cell_layout);

cellLayout.getCellWidth();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top